我在从 python 调用共享 c 库时遇到问题。该库加载良好,公开的 3 个函数之一是可调用的,并且可以按预期工作;但是,当向库中添加另一个函数时,我发现另外两个不起作用。发生的事情是 python 挂在实际的函数调用上,只是在什么都不做的情况下旋转。python 端和c 端都有详细的日志记录,我可以看出库中的函数甚至没有启动,因为没有编写任何调试文件。
以下是相关代码的一小段:
这是失败的 c 代码示例函数:
int genTest(char* filePath)
{
infoPrint(filePath, 2);
return EXIT_SUCCESS;
}
这是我调用它的python:
import ctypes as C
lg.create_log_entry('loading dll... from ' + str(lib_path) + str(lib_name))
myclib = C.CDLL(lib_path + lib_name)
lg.create_log_entry('loaded')
genTest = myclib.genTest
genTest.argtypes = [C.c_char_p]
genTest.restype = C.c_int
lg.create_log_entry('test start')
res = genTest(C.c_char_p(str(source_as_image)))
certirxlogging.create_log_entry('test successful')
此代码开始编写“测试开始”并挂起。就像我说的那样,这在 python 代码中其他地方的库中的另一个函数上运行良好,并且 python 没有给我任何错误,所以,我无法调试任何东西。有任何想法吗?