在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 (将#修改为@)