使用 install_name_tool -id 更改 dylib 库路径,没有任何变化

Changing dylib library path with install_name_tool -id, nothing changes

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

/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)

无法理解为什么它不会更改路径...

两期:

  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