Mac 上 Mono 中的 DllImport 出现 DllNotFoundException:错误的架构
我正在尝试与 Mac 上的 Mono 中的 ImageMagick 库进行互操作。我使用 MacPorts 安装了 ImageMagick 库,并验证了文件 libMagickWand.dylib 存在于目录 /opt/local/lib 中。我还在目录 /usr/local/lib 中创建了指向该文件的软链接。
这是我的 DllImport 语句:
[DllImport("libMagickWand", EntryPoint = "MagickWandGenesis")]
static extern void WandGenesis();
这是我的 App.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<dllmap dll="libMagickWand" target="/opt/local/lib/libMagickWand.dylib" />
</configuration>
并且,在调用 WandGenesis();
时,我收到一个 DllNotFoundException
,并显示消息“libMagickWand”。
我已阅读此页面,并且我认为我遵守了所有规则。还有什么我可以尝试的吗?
更新:
我使用 MONO_LOG_LEVEL=debug 运行 .exe。以下是相关信息:
Mono: DllImport error loading library 'dlopen(/opt/local/lib/libMagickWand.5.dylib, 9):
no suitable image found.
Did find: /opt/local/lib/libMagickWand.5.dylib: mach-o, but wrong architecture'.
架构错误:我在 32 位模式下运行 Snow Leopard,而且一直如此。我使用 MacPorts 安装了 ImageMagick,并使用来自 mono-project.com 的 Mac 软件包安装了 Mono。使用不同的架构会编译什么?
更新:
我想我发现了我的问题:
MacBook-Pro:lib ken$ lipo -info libMagickWand.5.dylib
Non-fat file: libMagickWand.5.dylib is architecture: x86_64
更新:
...但我仍然遇到问题。我似乎不知道如何用 i386 架构编译 ImageMagick。当我尝试使用标志来执行此操作时,它会抱怨其他编译为 64 位的库。
I'm trying to interop with the ImageMagick library in Mono on a Mac. I installed the ImageMagick library with MacPorts and have verified that the file libMagickWand.dylib exists in the directory /opt/local/lib. I've also created a soft link to that file in the directory /usr/local/lib.
Here's my DllImport statement:
[DllImport("libMagickWand", EntryPoint = "MagickWandGenesis")]
static extern void WandGenesis();
Here's my App.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<dllmap dll="libMagickWand" target="/opt/local/lib/libMagickWand.dylib" />
</configuration>
And, at the call to WandGenesis();
, I get a DllNotFoundException
, with the message 'libMagickWand'.
I've read this page and I think I'm following all the rules. Is there anything else I can try?
Update:
I ran the .exe with MONO_LOG_LEVEL=debug. Here is the pertinent information:
Mono: DllImport error loading library 'dlopen(/opt/local/lib/libMagickWand.5.dylib, 9):
no suitable image found.
Did find: /opt/local/lib/libMagickWand.5.dylib: mach-o, but wrong architecture'.
wrong architecture: I'm running Snow Leopard in 32-bit mode and always have. I installed ImageMagick with MacPorts, and I installed Mono with the Mac package from mono-project.com. What would have been compiled with a different architecture?
Update:
I think I found my problem:
MacBook-Pro:lib ken$ lipo -info libMagickWand.5.dylib
Non-fat file: libMagickWand.5.dylib is architecture: x86_64
Update:
...but I'm still having issues. I can't seem to figure out how to compile ImageMagick with i386 architecture. When I try to do so using flags, it complains about other libraries that were compiled as 64-bit.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更新:
Mac OS X 上的 Mono 是 32 位(至少通常情况下,您可以使用
mono --version
确认这一点),并且您正在尝试链接 64 位二进制文件,即不可能。您必须提供 32 位二进制文件(或使用 64 位单声道)。即使目标中只有库的文件名并且库已正确放置(或设置了 DYLD_LIBRARY_PATH),您是否也会遇到错误?在这种情况下,请提供使用 MONO_LOG_LEVEL=debug 执行的 mono 的输出。
Update:
Mono on Mac OS X is 32 bit (at least usually, you can confirm that with
mono --version
) and you are trying to link with 64bit binary which is not possible. You have to provide 32-bit binary (or use 64-bit Mono).Do you have the error even when only the library's file name is in the target and the library is placed appropriately (or the DYLD_LIBRARY_PATH set)? In such case please provide the output of mono executed with MONO_LOG_LEVEL=debug.