如何解决在Windows上使用ctypes为Python创建C包装
您好,我正在尝试为Python创建C包装函数,但遇到了一些麻烦。
这是一个重现问题的简单测试用例。 C函数所做的所有事情就是打印给它的字符串。
import ctypes
def test(hi):
fun = ctypes.CDLL(r"\cygwin64\home\User\test\test.so")
fun.print.argtypes = [ctype.c_char_p]
fun.print(hi)
test("pizza")
我得到的错误消息是。
Traceback (most recent call last):
File "C:\cygwin64\home\CCSS Student\test\kdtw.py",line 25,in <module>
test('pizza')
File "C:\cygwin64\home\CCSS Student\test\kdtw.py",line 19,in test
fun = ctypes.CDLL(r"\cygwin64\home\CCSS Student\test\test.so")
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\ctypes\__init__.py",line >364,in __init__
self._handle = _dlopen(self._name,mode)
OSError: [WinError 126] The specified module could not be found
我尝试给出完整路径(包括驱动器)和文件名,并且该文件位于同一目录中。 C文件将编译为.so文件。请注意,我在Windows上可能会有所作为。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。