Xcode 不断在错误的路径中搜索 dylib

发布于 2024-10-15 17:05:12 字数 2705 浏览 4 评论 0原文

这是我的错误:

dyld: Library not loaded: /usr/local/lib/libofa.0.dylib
Referenced from: /sers/david/Projekte/Test/build/Debug/Test.app/Contents/MacOS/Test
Reason: image not found

我已经做了一些研究并使用 install_name_tool 更改了 dylib 内的路径:

davids-macbook:Test david$ otool -L libofa.0.0.0.dylib 
libofa.0.0.0.dylib:
@executable_path/../Frameworks/libofa.0.0.0.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.1)
/System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate (compatibility version 1.0.0, current version 4.0.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.9.0)

但是 Xcode 一直在 /usr/lib/ 中搜索它:

build/Debug/Test.app/Contents/MacOS/Test:
/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 15.0.0)
/System/Library/Frameworks/AudioToolbox.framework/Versions/A/AudioToolbox (compatibility version 1.0.0, current version 1.0.0)
/opt/local/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
@executable_path/../Frameworks/TagLib.framework/Versions/A/TagLib (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/QTKit.framework/Versions/A/QTKit (compatibility version 1.0.0, current version 1.0.0)
/opt/local/lib/libexpat.1.dylib (compatibility version 7.0.0, current version 7.2.0)
/System/Library/Frameworks/Quartz.framework/Versions/A/Quartz (compatibility version 1.0.0, current version 1.0.0)
/opt/local/lib/libcurl.4.dylib (compatibility version 7.0.0, current version 7.0.0)
/usr/local/lib/libofa.0.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.9.0)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 103.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0)
/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 227.0.0)
/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 44.0.0)
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 550.29.0)
/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 751.29.0)
/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1038.32.0)

有没有办法在 Xcode 中设置它???谢谢

编辑:该库不是 Xcode 项目。它使用 ./configure 构建;制作

Thats my error:

dyld: Library not loaded: /usr/local/lib/libofa.0.dylib
Referenced from: /sers/david/Projekte/Test/build/Debug/Test.app/Contents/MacOS/Test
Reason: image not found

I've done some research and changed the path inside the dylib with install_name_tool:

davids-macbook:Test david$ otool -L libofa.0.0.0.dylib 
libofa.0.0.0.dylib:
@executable_path/../Frameworks/libofa.0.0.0.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.1)
/System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate (compatibility version 1.0.0, current version 4.0.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.9.0)

But Xcode keeps searching for it in /usr/lib/:

build/Debug/Test.app/Contents/MacOS/Test:
/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 15.0.0)
/System/Library/Frameworks/AudioToolbox.framework/Versions/A/AudioToolbox (compatibility version 1.0.0, current version 1.0.0)
/opt/local/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
@executable_path/../Frameworks/TagLib.framework/Versions/A/TagLib (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/QTKit.framework/Versions/A/QTKit (compatibility version 1.0.0, current version 1.0.0)
/opt/local/lib/libexpat.1.dylib (compatibility version 7.0.0, current version 7.2.0)
/System/Library/Frameworks/Quartz.framework/Versions/A/Quartz (compatibility version 1.0.0, current version 1.0.0)
/opt/local/lib/libcurl.4.dylib (compatibility version 7.0.0, current version 7.0.0)
/usr/local/lib/libofa.0.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.9.0)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 103.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0)
/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 227.0.0)
/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 44.0.0)
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 550.29.0)
/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 751.29.0)
/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1038.32.0)

Is there a way to set this in Xcode??? Thanks

Edit: The library is not a Xcode project. Its build with ./configure; make

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浸婚纱 2024-10-22 17:05:12

通常我会这样做:

  1. 将库的安装目录设置为@rpath。这会将安装名称设置为@rpath/libofa.0.0.0.dylib。如果您自己构建库,则可以在 Xcode 中进行设置;否则,请使用 install_name_tool 进行更改。
  2. 将使用该库的应用程序的运行路径搜索路径设置为包含该库的目录位置。例如,如果您将库放在应用程序的 Frameworks 目录中,则需要将运行路径搜索路径设置为@executable_path/../Frameworks (或@loader_path/../Frameworks)。

这篇博文这个了解更多细节。

Normally what I do is this:

  1. Set the Installation Directory of the library to @rpath. This will set the install name to @rpath/libofa.0.0.0.dylib. If you're building the library yourself, you can set this in Xcode; otherwise, use install_name_tool to change it.
  2. Set the Runpath Search Paths of the application using the library to the location of the directory containing the library. For example, if you put the library in the app's Frameworks directory, you'd set Runpath Search Paths to @executable_path/../Frameworks (or @loader_path/../Frameworks).

This blog post and this one go into more detail.

冬天旳寂寞 2024-10-22 17:05:12

确保从developer.apple.com 安装命令行工具,然后将库添加到您的项目中。在 Xcode 中运行以下脚本:目标 » 构建阶段 » 运行脚本并执行:

install_name_tool -id @executable_path/../Frameworks/librayName.dylib "$SRCROOT/librayName.dylib"

注意:dylib 名称前不需要 ' 或 ""

Make sure to install the command line tools from developer.apple.com and then add the library in your project. Run the following script in your Xcode: Targets » Build Phases » Run Script and just execute:

install_name_tool -id @executable_path/../Frameworks/librayName.dylib "$SRCROOT/librayName.dylib"

Note: NO ' or "" required before dylib name

任性一次 2024-10-22 17:05:12

在寻求解决方案之前,您应该了解 MAC 中的依赖库“dylib”与 Windows 中的依赖库“dll”相比有何新功能。

dylib 与 dll 的主要区别在于“安装名称”。安装名称是嵌入到动态库中的路径,表示运行时在哪里可以找到该库。无论您将 dylib 复制到哪里,它都将始终指向旧路径(除非不更改安装名称)。
您可以使用如下命令

otool -L a.dylib

了解原始搜索路径(安装名称) (只需拖动dylib代替a.dylib)

有关安装名称的更多详细信息,请参阅此链接

现在,更改 dylib("install name") 新位置的解决方案只需使用 install_name_tool 如下

install_name_tool -change *old path of dylb* *new path of dylib*

您可以通过上面描述的otool -L命令获取旧路径。(旧路径即原始路径)

install_name_tool -change也可以更改dylib和可执行文件的搜索路径。

您可以通过在项目中的 Run script 文件中写入来在 Xcode 中使用它。

Before going for solution, you should know what is new with dependent library "dylib" in MAC as compare to dependent library "dll" in windows.

The major difference in dylib vs dll is "install name". The install name is a path baked into the dynamic library that says where to find the library at runtime. It does not matter where you copy your dylibs, It will always point to old path(except without changing install name).
You can know original search path(install name) by using command as below

otool -L a.dylib

(just drag dylib in place of a.dylib)

For more detail about install name, refer this link.

Now, solution for changing the new location for dylib("install name") is just use install_name_tool as below

install_name_tool -change *old path of dylb* *new path of dylib*

you can get old path by otool -L command described above already.(old path i.e. original path)

install_name_tool -change can change search path of dylib and executable as well.

You can use this in Xcode by writing in Run script file in your project.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文