Python调用C的DLL(动态链接库)

开发环境:mingw64位,python3.6 64位

参考博客:

mingw编译dll:

https://blog.csdn.net/liyuanbhu/article/details/42612365

python调用dll:

https://www.cnblogs.com/cnpirate/p/5939446.html

编写 dlltest.c

//dlltest.c  
int Double(int x)  
{  
    return x * 2;  
}  

编译为dll

gcc dlltest.c -shared -o dlltest.dll -Wl,--out-implib,dlltest.lib

得到lib和dll文件

在python中调用:

from ctypes import *
dll = cdll.LoadLibrary('DLL/dlltest.dll')
a=dll.Double(123)
print(type(a))
print(a)

输出:

<class 'int'>
246
原文地址:https://www.cnblogs.com/TQCAI/p/8878748.html