使用Mono可执行文件捆绑.dylib文件 [英] Bundling .dylib files with mono executable

查看:135
本文介绍了使用Mono可执行文件捆绑.dylib文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,我想将一个特定的dylib与它捆绑在一起. 我正在使用"dylibbundler"将dylib及其依赖项复制到可执行文件夹.这是我正在使用的命令:

I have an application and I'd like to bundle a specific dylib along with it. I'm using "dylibbundler" to copy the dylib along with dependencies to the executable folder. Here's the command I'm using:

dylibbundler -od -b -x /opt/local/lib/libil.dylib -d ./libs/ -p @executable_path/libs/

dylibbundler与可执行文件位于同一目录中.该工具在库及其所有依赖项上递归运行"install_name_tool"(并将它们复制到指定目录).在./libs/libil.1.dylib上运行otool -L返回:

dylibbundler is located in the same directory with the executable. The tool recursively runs "install_name_tool" on the library and all of its dependencies (and copies them to a specified directory). Running otool -L on the ./libs/libil.1.dylib returns:

@executable_path/libs/libIL.1.dylib (compatibility version 3.0.0, current version 3.0.0)
@executable_path/libs/libtiff.5.dylib (compatibility version 8.0.0, current version 8.0.0)
@executable_path/libs/liblzma.5.dylib (compatibility version 6.0.0, current version 6.4.0)
@executable_path/libs/libpng15.15.dylib (compatibility version 30.0.0, current version 30.0.0)
@executable_path/libs/libmng.1.dylib (compatibility version 2.0.0, current version 2.0.0)
@executable_path/libs/liblcms.1.dylib (compatibility version 2.0.0, current version 2.19.0)
@executable_path/libs/libjasper.1.dylib (compatibility version 2.0.0, current version 2.0.0)
@executable_path/libs/libjpeg.9.dylib (compatibility version 10.0.0, current version 10.0.0)
@executable_path/libs/libIlmImf.6.dylib (compatibility version 7.0.0, current version 7.0.0)
@executable_path/libs/libImath.6.dylib (compatibility version 7.0.0, current version 7.0.0)
@executable_path/libs/libHalf.6.dylib (compatibility version 7.0.0, current version 7.0.0)
@executable_path/libs/libIlmThread.6.dylib (compatibility version 7.0.0, current version 7.0.0)
@executable_path/libs/libIex.6.dylib (compatibility version 7.0.0, current version 7.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
@executable_path/libs/libz.1.dylib (compatibility version 1.0.0, current version 1.2.7)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 52.0.0)

在我看来,它已正确复制了所有内容.但是当我运行我的应用程序时,我不断收到相同的异常:

It seems to me that it has copied everything over correctly. But when I run my application, I keep getting the same exception:

Unhandled Exception: System.DllNotFoundException: ./libs/libIL.1.dylib
Unhandled Exception: System.DllNotFoundException: @executable_path/libs/libIL.1.dylib
Unhandled Exception: System.DllNotFoundException: libs/libIL.1.dylib

如您所见,我尝试了3种不同的引用库的方法,但始终找不到它.

As you can see, I've tried 3 different ways of referencing to the library, but it always fails to find it.

任何帮助将不胜感激,我几个月来一直在努力解决这个问题.

Any help would be greatly appreciated, I've been trying to solve this issue for months now.

更新: 如果我指定dylib的绝对路径,它将找到它,但是会抱怨依赖项:

UPDATE: If I specify an absolute path to the dylib, it finds it, but then complains about the dependencies:

Mono: DllImport error loading library 'dlopen(/Users/me/myapp/libs/libil.1.dylib, 9): Library not loaded: @executable_path/libs/libtiff.5.dylib
  Referenced from: /Users/me/myapp/libs/libil.1.dylib
  Reason: image not found'.

在我看来,@executable_path并没有替换为实际的绝对可执行路径.

It seems to me that @executable_path isn't being substituted with the actual absolute executable path.

推荐答案

请记住,本机可执行文件不是myapp.exe,而是单二进制文件.

Have in mind that the native executable is not myapp.exe, it's the mono binary.

尝试按另一个答案中所述设置DYLD_LIBRARY_PATH(请注意,您必须在执行应用程序之前进行设置,因为动态库加载器会在应用程序加载到内存时读取此值,就像在执行Main方法之前一样).

Try setting DYLD_LIBRARY_PATH as mentioned in a different answer (note that you have to set it before executing your app, since the dynamic library loader reads this value when the application is loaded into memory, way before your Main method is executed).

这篇关于使用Mono可执行文件捆绑.dylib文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆