簡體   English   中英

用ctypes加載.dll

[英]Loading .dll with ctypes

我有一個.dll與某些其他(Sundials ODE求解器).dll的依賴關系。 我將Windows 8.1與mingw一起使用來編譯和鏈接用於.dll的C代碼。 嘗試使用Python和ctypes加載它們時,出現一個帶有System error: cannot find libsundials_cvode.dll since it does not exist on the computer的彈出窗口System error: cannot find libsundials_cvode.dll since it does not exist on the computer並且當您關閉彈出窗口時,Python吐出WindowsError: [Error 126] Cannot find the module無法理解為什么會這樣,因為gcc可以很好地編譯和鏈接文件而沒有錯誤(是的,它們確實存在)...我什至試圖將相關的dll復制到我的python腳本所在的目錄中,但沒有成功。

我運行以下編譯和鏈接器命令,沒有任何警告或錯誤

gcc -c -I c:\sundials\include cfile.c
gcc -shared -o clib.dll cfile.o -L. C:\sundials\instdir\lib\libsundials_cvode.dll -L. C:\sundials\instdir\lib\libsundials_nserial.dll

我的python測試腳本給出上述錯誤是

import ctypes
lib = ctypes.cdll.LoadLibrary('clib.dll')

我是gcc和c的初學者,但是對Python很有經驗。 有什么建議可能是什么原因?

參見Wikipedia 動態鏈接庫

“ ...除非您的DLL是組件對象模型(COM)服務器,否則DLL文件必須放置在PATH環境變量中列出的目錄之一,默認系統目錄中,或者與使用以下命令的程序位於同一目錄中它...”

因此,將C:\\sundials\\instdir\\lib到PATH環境中。 變量。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM