我有一个应用程序,我想将一个特定的 dylib 与它捆绑在一起。我正在使用“dylibbundler”将 dylib 以及依赖项复制到可执行文件夹中。这是我正在使用的命令:
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 返回:
@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)
在我看来,它已经正确地复制了所有内容。但是当我运行我的应用程序时,我不断收到同样的异常:
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 种不同的方式来引用该库,但总是找不到它。
任何帮助将不胜感激,几个月来我一直在尝试解决这个问题。
更新: 如果我指定 dylib 的绝对路径,它会找到它,但随后会抱怨依赖关系:
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 并没有被实际的绝对可执行路径取代。