python - Python调用c++ DLL:依赖其他dll调用c++函数时的访问冲突写法
问题描述
我正在尝试生成一个需要在 python 中调用的 c++ dll。
c++ dll 中的一些函数调用来自第三方静态库的函数。(在 mvc 中,我在 Additional include 目录中添加了所需的内容;Additional Library Directories and Additional Dependencies (xxx.lib) )
在 c++ 中一切正常。
在python中导出我在.h中做的
#define EXPORT_SYMBOL __declspec(dllexport)
#ifdef __cplusplus
extern "C" {
#endif
EXPORT_SYMBOL void func1(void);
EXPORT_SYMBOL void func2(void);
EXPORT_SYMBOL float testAdd(float x, float y);
#ifdef __cplusplus
}
#endif
testAdd 只是一个基本的返回 x+y。func1 是一个做基本工作的函数,最后是 puts("xxx"),不依赖于第三方库。func2 依赖于第三方库中的函数。
在蟒蛇中:
import ctypes
mydll = ctypes.CDLL("mydll.dll")
mydll.Add.argtypes = [ctypes.c_float,ctypes.c_float]
mydll.Add.restype = ctypes.c_float
print(mydll.Add(4,5))
print(mydll.func1())
返回 9.0 和 xxx。
但是当我这样做时: mydll.func2() 我得到:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: exception: access violation writing 0x00000000B3C24F00
如果我第二次调用它,它“工作”,该函数不会返回我想要的,但它会返回一些东西。所以首先我有一个我无法识别的不一致问题。
其次,从 c++ 或 python 调用时,c++ func2 中某些第三方函数的返回似乎完全不同,这似乎根本不合逻辑。
但是当我在func2中做一些printf。我从 c++ 控制台程序中调用 .dll 我有一些东西,而从 python 中,我没有相同的结果。
解决方案
推荐阅读
- c# - 一次显示多个权限 xamarin 表单
- jquery - 我想在单击按钮时在 DataTable 中填充数据,默认情况下它应该显示没有可用的数据
- mysql - 如何第一次填充具有多个表的 SQL 数据库
- java - 如何调用jar类
- python - 如何在 Tensorflow 中将小图像添加到大图像?
- python - 用熊猫分组列表
- node.js - 在 Node.js 中为测试模拟特定的读取文件错误
- java - 如何让java在将输入分配给变量之前等待输入以避免java.util.NoSuchElementException
- c# - 如何在 C# 中遍历对象中的所有字段?
- kotlin - 为什么匕首需要提供我不想提供的实体?