install_name_tool - ShenYj/ShenYj.github.io GitHub Wiki

install_name_tool

一个可以更改动态库 name 等信息的工具

NAME
       install_name_tool - change dynamic shared library install names

SYNOPSIS
       install_name_tool [-change old new ] ... [-rpath old new ] ... [-add_rpath new ] ... [-delete_rpath new ] ... [-id name] file

DESCRIPTION
       Install_name_tool changes the dynamic shared library install names and or adds, changes or deletes the rpaths recorded in a
       Mach-O binary.  For this tool to work when the install names or rpaths are larger the binary should be built with the ld(1)
       -headerpad_max_install_names option.

       -change old new
              Changes the dependent shared library install name old to new in the specified Mach-O binary.  More than one of these
              options can be specified.  If the Mach-O binary does not contain the old install name in a specified -change option the
              option is ignored.

       -id name
              Changes the shared library identification name of a dynamic shared library to name.  If the Mach-O binary is not a
              dynamic shared library and the -id option is specified it is ignored.

       -rpath old new
              Changes the rpath path name old to new in the specified Mach-O binary.  More than one of these options can be specified.
              If the Mach-O binary does not contain the old rpath path name in a specified -rpath it is an error.

       -add_rpath new
              Adds the rpath path name new in the specified Mach-O binary.  More than one of these options can be specified.  If the
              Mach-O binary already contains the new rpath path name specified in -add_rpath it is an error.

       -delete_rpath old
              deletes the rpath path name old in the specified Mach-O binary.  More than one of these options can be specified.  If the
              Mach-O binary does not contains the old rpath path name specified in -delete_rpath it is an error.

e.g.

  • 为一个已存在的动态库修改 name

    格式: install_name_tool -参数 动态库文件路径 动态库名称

    install_name_tool -id /Users/shenyj/framework动态库/Frameworks/TestExample.framework/TestExample TestExample
  • 再次通过 otool -l TestExample | grep 'ID' -B 5 -A 5 命令查看 Load Command

    ❯ otool -l TestExample | grep 'ID' -B 5 -A 5
    maxprot 0x00000001
    initprot 0x00000001
    nsects 0
        flags 0x0
    Load command 4
            cmd LC_ID_DYLIB
        cmdsize 200
            name /Users/shenyj/framework动态库/Frameworks/TestExample.framework/TestExample (offset 24)
    time stamp 1 Thu Jan  1 08:00:01 1970
        current version 0.0.0
    compatibility version 0.0.0
    --
        extreloff 0
            nextrel 0
        locreloff 0
            nlocrel 0
    Load command 9
        cmd LC_UUID
    cmdsize 24
        uuid 751402DD-EBFE-36BD-9D78-C918909190BD
    Load command 10
        cmd LC_BUILD_VERSION
    cmdsize 32
    
⚠️ **GitHub.com Fallback** ⚠️