【问题标题】:Changing dylib library path with install_name_tool -id, nothing changes使用 install_name_tool -id 更改 dylib 库路径,没有任何变化
【发布时间】:2021-06-21 01:19:14
【问题描述】:

我正在尝试将可执行文件放在一起发送到另一台计算机。 otool -L "exec_name" 返回:

/usr/local/opt/glfw/lib/libglfw.3.dylib (compatibility version 3.0.0, current version 3.3.0)

尝试将其更改为我的可执行目录:

install_name_tool -id @executable_path/libglfw.3.3.dylib libglfw.3.3.dylib

它会发出警告:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/install_name_tool: warning: changes being made to the file will invalidate the code signature in: libglfw.3.3.dylib (for architecture x86_64)

但没有任何变化,otool -L 仍然显示:

/usr/local/opt/glfw/lib/libglfw.3.dylib (compatibility version 3.0.0, current version 3.3.0)

我也试过

install_name_tool -id @executable_path/libglfw.3.3.dylib libglfw.3.dylib

这给出了一个错误:

error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/install_name_tool: can't open file: libglfw.3.dylib (No such file or directory)

不明白为什么它不会改变路径...

【问题讨论】:

    标签: xcode macos dylib otool install-name-tool


    【解决方案1】:

    两个问题:

    1. 这是@executable_path,而不是@executive_path

    2. 您需要在库和链接到它的二进制文件中更改安装名称:

      install_name_tool -id @executable_path/libglfw.3.3.dylib libglfw.3.3.dylib
      install_name_tool -change /usr/local/opt/glfw/lib/libglfw.3.dylib @executable_path/libglfw.3.3.dylib [exec_name]
      

    有关安装名称如何工作的更深入解释,请参阅this answer of mine

    【讨论】:

    • 哇,感谢您的回答和链接,它非常有帮助。我仍然不明白为什么 xcode 与 /usr/local/opt/glfw/lib/libglfw.3.dylib 链接,当我明确告诉它与来自 Cellar 的链接时:/usr/local/Cellar/glfw/3.3。 4/lib/libglfw.3.3.dylib 。我了解/usr/local/opt/glfw/lib/libglfw.3.dylib 是指向/usr/local/Cellar/glfw/3.3.4/lib/libglfw.3.3.dylib 的别名,仍然不知道为什么不会拿我想要的。但这是另一个问题。
    • 因为它不仅仅使用您提供的路径。它读取该路径的文件,解析其加载命令,并使用嵌入在该二进制文件中的安装名称。所以符号链接完全没有改变。
    • /usr/local/Cellar/glfw/3.3.4/lib/libglfw.3.3.dylib 嵌入了/usr/local/opt/glfw/lib/libglfw.3.dylib,正确?
    • 这是合乎逻辑的结论,是的。
    • 不幸改名后:@rpath/libglfw.3.3.dylib(兼容版本3.0.0,当前版本3.3.0)(我做了rpath是为了和其他库保持一致),我开始搞定了以下错误:“无法启动“AppName”域:IDEDebugSessionErrorDomain 代码:3 失败原因:“AppName”未能启动或在调试器附加到它之前退出。请验证“AppName”是否具有允许它的有效代码签名要在“我的 Mac”上启动。有关更多诊断信息,请参阅崩溃日志和系统日志。
    猜你喜欢
    • 2012-11-09
    • 1970-01-01
    • 1970-01-01
    • 2012-05-08
    • 2020-12-03
    • 2020-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多