简体   繁体   English

无法在python中加载c ++ DLL

[英]could not load c++ DLL in python

I am trying to use a C++ .dll in Python, but I can't even load it. 我试图在Python中使用C ++ .dll ,但我甚至无法加载它。 I am trying the following python code to load it: 我正在尝试以下python代码来加载它:

from ctypes import cdll
mydll = cdll.LoadLibrary('SORT_DLL.dll')

But when I try to run this I get: 但当我尝试运行时,我得到:

D:\...\src\SORT_DLL\Debug>UseDll.py
Traceback (most recent call last):
  File "D:\...\src\SORT_DLL\Debug\UseDll.py", line 2, in
 <module>
    mydll = cdll.LoadLibrary('SORT_DLL.dll')
  File "C:\Python27\lib\ctypes\__init__.py", line 443, in LoadLibrary
    return self._dlltype(name)
  File "C:\Python27\lib\ctypes\__init__.py", line 365, in __init__
    self._handle = _dlopen(self._name, mode)
WindowsError: [Error 193] %1 ist keine zulõssige Win32-Anwendung

The last sentence means "%1 is not a valid Win32 application" in English. 最后一句用英语表示“%1不是有效的Win32应用程序”。

I already looked it up at http://docs.python.org/2/library/ctypes.html#module-ctypes , but this didn't lead to a solution for my problem. 我已经在http://docs.python.org/2/library/ctypes.html#module-ctypes上查了一下,但这并没有为我的问题找到解决方案。

Sounds like you have an incompatible version of Python installed or the DLL was compiled using the wrong settings. 听起来你安装了不兼容的Python版本,或者使用错误的设置编译了DLL。 The DLL and the Python interpreter both have to be either 32 or 64 Bit. DLL和Python解释器都必须是32位或64位。

Refer to this answer: https://stackoverflow.com/a/10163943/953887 请参阅此答案: https//stackoverflow.com/a/10163943/953887

"ctypes doesn't work with C++, which the [DLL] example is written in." “ctypes不适用于编写[DLL]示例的C ++。”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM