Fix missing libraries of an existing Mac OS binary by adding a correct @rpath command

  • Post published:April 8, 2016

Adding missing library path to an existing OS X binary:
For example: open tracker (see https://github.com/opentrack/opentrack) misses the correct relative @rpath:
otool -l /Applications/opentrack.app/Contents/MacOS/opentrack.bin | grep @rpath
name @rpath/QtWidgets.framework/Versions/5/QtWidgets (offset 24)
name @rpath/QtGui.framework/Versions/5/QtGui (offset 24)
name @rpath/QtNetwork.framework/Versions/5/QtNetwork (offset 24)
name @rpath/QtCore.framework/Versions/5/QtCore (offset 24)

Where @rpath is at:
Load command 28
cmd LC_RPATH
cmdsize 56
path /Users/sthalik/dev/opentrack/build/install (offset 12)
Load command 29
cmd LC_RPATH
cmdsize 56
path /Users/sthalik/Qt5.5.1/5.5/clang_64/lib (offset 12)

Wrong path set for local Qt’s libraries

In order to fix this: we should add a custom @rpath for all libraries not being deployed with the executable or being linked with libs only being locally available:
For example adding local Qt libs to opentracker.bin:
install_name_tool -add_rpath /Applications/Qt/5.5/clang_64/lib /Applications/opentrack.app/Contents/MacOS/opentrack.bin

More generally speaking:
install_name_tool -add_rpath “absolute path to libs to be added to the executable” “absolute path to the executable”

Check the results:
otool -l /Applications/opentrack.app/Contents/MacOS/opentrack.bin
Load command 32
cmd LC_RPATH
cmdsize 48
path /Applications/Qt/5.5/clang_64/lib (offset 12)