install_name_tool -change静默失败,并忽略-headerpad_max_install_names标志

Ale*_*lds 5 macos gcc dylib otool install-name-tool

我有一个命令行可执行文件,其中包含指向dylib的链接,这些链接在分发时不会位于所返回的指定位置otool -L

例如,给定一个二进制文件foo

$ otool -L foo
  /opt/local/lib/libgcc/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.18.0)
  ...
Run Code Online (Sandbox Code Playgroud)

在我的安装程序中,我有一个试图install_name_tool -change用于修复此问题的安装后脚本,以便foo在其新位置链接到dylib。

例如:

$ sudo install_name_tool -change /opt/local/lib/libgcc/libstdc++.6.dylib /somewhere/else/more/sensible/libstdc++.6.dylib foo
Run Code Online (Sandbox Code Playgroud)

但是,此更改将被忽略,并且会静默失败。当我otool -L再次运行时:

$ otool -L foo
  /opt/local/lib/libgcc/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.18.0)
  ...
Run Code Online (Sandbox Code Playgroud)

没有改变。

我正在编译胖二进制文件,并尝试将-headerpad_max_install_names编译标志添加到32位Makefile中。这并没有解决问题,因为它install_name_tool -change仍然会静默失败。

我读到-headerpad_max_install_names在64位平台上没有任何作用,但是无论如何我还是将其添加到了64位Makefile中。可以预见,这也不能解决问题。

如何解决我的编译过程,以便最终可以更改链接的dylib的路径install_name_tool