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