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

Posted TQCAI

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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

 

以上是关于Python调用C的DLL(动态链接库)的主要内容,如果未能解决你的问题,请参考以下文章