开发环境: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

 

相关文章:

  • 2022-12-23
  • 2021-11-05
  • 2022-12-23
  • 2021-11-21
  • 2022-02-10
  • 2021-12-21
  • 2022-12-23
猜你喜欢
  • 2021-08-31
  • 2021-11-13
  • 2021-06-19
  • 2021-11-20
相关资源
相似解决方案