I have a library: libfoo.dylib. The problem is illustrated in the commands:
$ install_name_tool -id "@rpath/libfoo.dylib" libfoo.dylib $ install_name_tool -add_rpath "@executable_path/" libfoo.dylib $ gcc -o foo foo.c -lfoo $ ./foo #<==== I want this to work dyld: Library not loaded: @rpath/libfoo.dylib Referenced from: ~/./foo Reason: image not found $ install_name_tool -add_rpath "@executable_path/" foo #<=== I dont want to have to specify here where to look for the library $ ./foo Hello World
How do I achieve the goal of not having to specify at executable compile where the library is?
libfoo.dylib
with-headerpad_max_install_names
to ensure there's enough room for the names you are trying to add. Oncelibfoo.dylib
has its install name, thenfoo
will be able to link to it regardless of the location of the program. – Leak