在OSX上打印可执行文件的path

我想使用install_name_tool来更改可执行文件的path,但我无法弄清楚rpath是什么。 install_name_tool要求在命令行上给出旧的和新的rpath。 我可以使用什么命令在OSX下打印可执行文件的path?

首先,了解可执行文件不包含单个rpath条目,而是包含一个或多个条目的数组。

其次,您可以使用otool列出图像的rpath条目。 使用otool -l ,你会得到如下的输出,最后是rpath条目:

 Load command 34 cmd LC_LOAD_DYLIB cmdsize 88 name /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (offset 24) time stamp 2 Wed Dec 31 19:00:02 1969 current version 1038.32.0 compatibility version 45.0.0 Load command 35 cmd LC_RPATH cmdsize 40 path @loader_path/../Frameworks (offset 12) 

查找LC_RPATH命令并记下path条目下的path

我目前正在编写几个用于处理DYLD的Bash-3脚本,并且这个脚本回答了这个问题,所以我把它作为参考:

 #! /bin/bash # ######################################################################### # if [ ${#} -eq 0 ] then echo " Usage: ${0##*/} FILE... List rpaths in FILEs " exit 0 fi # ######################################################################### # shopt -s extglob # ######################################################################### # for file in "${@}" do if [ ! -r "${file}" ] then echo "${file}: no such file" 1>&2 continue fi if ! [[ "$(/usr/bin/file "${file}")" =~ ^${file}:\ *Mach-O\ .*$ ]] then echo "${file}: is not an object file" 1>&2 continue fi if [ ${#} -gt 1 ] then echo "${file}:" fi IFS_save="${IFS}" IFS=$'\n' _next_path_is_rpath= while read line do case "${line}" in *(\ )cmd\ LC_RPATH) _next_path_is_rpath=yes ;; *(\ )path\ *\ \(offset\ +([0-9])\)) if [ -z "${_next_path_is_rpath}" ] then continue fi line="${line#* path }" line="${line% (offset *}" if [ ${#} -gt 1 ] then line=$'\t'"${line}" fi echo "${line}" _next_path_is_rpath= ;; esac done < <(/usr/bin/otool -l "${file}") IFS="${IFS_save}" done # ######################################################################### # 

'希望能帮助到你 ;-)

注:有人知道一些Bash-3技巧可以用于这个脚本吗?

我发现我可以使用otool -D在osx上打印共享库的安装名称。

而且,我可以通过将-id标志传递给install_name_tool: install_name_tool -id“@ rpath / my / path mylib 来直接设置安装名称而不引用旧的安装名称

我只是使用otool命令

 otool -L <my executable> 

它打印出rpath字段。 不需要任何长的脚本。