【问题标题】:Loading .dll with ctypes使用 ctypes 加载 .dll
【发布时间】:2015-08-05 14:21:24
【问题描述】:

我有一个依赖于其他一些(日晷 ODE 求解器).dll 的 .dll。我使用带有 mingw 的 windows 8.1 来编译和链接我用于 .dll 的 c 代码。当尝试使用 Python 和 ctypes 加载它们时,我得到一个带有 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 非常有经验。任何建议可能是什么原因?

【问题讨论】:

  • 如果将 C:\sundials\instdir\lib 添加到 PATH 会发生什么?
  • 这似乎很有魅力!伟大的安托,谢谢你的回答。如果您将其作为单独的答案发布,我会为您接受。

标签: python c gcc dll linker


【解决方案1】:

参见维基百科Dynamic-link library:

"...除非您的 DLL 是组件对象模型 (COM) 服务器,否则 DLL 文件必须放在 PATH 环境变量中列出的目录之一、默认系统目录或与使用它的程序相同的目录..."

所以,将C:\sundials\instdir\lib 添加到您的 PATH 环境中。变量。

【讨论】:

    猜你喜欢
    • 2012-10-19
    • 1970-01-01
    • 2011-02-28
    • 2010-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-30
    • 1970-01-01
    相关资源
    最近更新 更多