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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM