IronPython cdll无法加载库。如果不使用IronPython,则可以使用

我有一个加载'c'dll的python脚本,在使用python 2.7(Anaconda)时可以正常工作。这是我用来测试错误的测试脚本:


import os

import ctypes

ctypes.cdll.LoadLibrary(os.path.abspath("a_c_library.dll"))

使用python 2.7:执行时,此方法工作正常 python test.py。没有错误出现,以后我也可以使用该库。


如果我在C#程序中使用IronPython,或者甚至仅使用像这样的命令行: "C:\Program Files\IronPython 2.7\ipy.exe" test.py或ipy32.exe,都会出现以下错误:


Traceback (most recent call last):

  File "test.py", line 3, in <module>

  File "C:\Program Files\IronPython 2.7\Lib\ctypes\__init__.py", line 445, in LoadLibrary

  File "C:\Program Files\IronPython 2.7\Lib\ctypes\__init__.py", line 366, in __init__

OSError: IronPython.Runtime.Exceptions.OSException: cannot load library **THE ABSOLUTE PATH TO MY DLL WHICH IS CORRECT**

为什么在使用IronPython时无法加载库?我在Windows 10上。同样,在使用常规python时,我可以使用该库,但是IronPython用相同的代码给我一个错误。


谢谢你的时间!


编辑:我试图直接使用该代码从C#加载相同的dll:


[DllImport("a_c_library.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "AFunction")]

static extern IntPtr Unmanged_AFunction();

然后调用未管理的函数,我得到以下错误:System.BadImageFormatException: 'An attempt was made to load a program with an incorrect format.尝试使用x86和x64构建。x64给出了此错误:System.DllNotFoundException: 'Unable to load DLL 'a_c_library.dll': The specified module could not be found.即使将dll复制到与x64 exe相同的位置。


慕工程0101907
浏览 236回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python