为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

慕工程0101907 2021-04-17 18:42:14
我有一个加载'c'dll的python脚本,在使用python 2.7(Anaconda)时可以正常工作。这是我用来测试错误的测试脚本:import osimport ctypesctypes.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相同的位置。
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 235 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号