Remove default search path when linking new dylib.

xcode macos linker shared-libraries

411 просмотра

1 ответ

1594 Репутация автора

I'm trying to link new dylib to my executable, but it link it with absolute path (/usr/local/lib/) how can I remove this default path from the used shared libraries ?

otool -L ../Build/Products/Debug/myexec

/usr/local/lib/libmylib.dylib (compatibility version 1.0.0, current version 1.0.0)
Автор: Zohar81 Источник Размещён: 18.07.2016 08:29

Ответы (1)

1 плюс

7230 Репутация автора


On OS X, install_name_tool command can change dynamic link libs.

  • -change old new binary option will change one or several libs' location.
  • -rpath old new binary will reset rpath to a new one.
  • -delete_rpath old binary will remove the current one.
  • -add_rpath new binary will add a new path.

However, there may be a small trouble: it seems this cmd line tool can only set the binary's rpath, not the system rpath, so that /usr/local/lib cannot be removed by -delete_rpath option.

In such case, the only option is -change old new.

To check rpath:

$ otool -l that_exec |grep -C 5 LC_RPATH
      cmd LC_DATA_IN_CODE
  cmdsize 16
  dataoff 13152
 datasize 0
Load command 40
          cmd LC_RPATH
      cmdsize 32
         path /the_binarys_rpath/here (offset 12)
Автор: halfelf Размещён: 29.07.2016 03:04
Вопросы из категории :