Related, but do not answer the question:
On OSX, I have a dynamic library provided by a packager manager, installed in a non
standard directory, which install_name is just the filename. For example:
$ ROOT=$PWD
$ mkdir $ROOT/foo
$ cd $ROOT/foo
$ echo 'int foo(int a, int b){return a+b;}' > foo.c
$ clang foo.c -dynamiclib -install_name libfoo.dylib -o libfoo.dylib
I don't want to change (absolute path, @RPATH, ...) the install_name of
libfoo.dylib using install_name_tool -id
.
Now I link a program with the library, for example:
$ mkdir $ROOT/bar
$ cd $ROOT/bar
$ echo 'int foo(int,int); int main(){return foo(2,4);}' > main.c
$ clang main.c -L../foo -lfoo
The program can't run:
$ ./a.out
dyld: Library not loaded: libfoo.dylib
Referenced from: $ROOT/bar/./a.out
Reason: image not found
Trace/BPT trap: 5
because:
$ otool -L ./a.out
./a.out:
libfoo.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)
I can change the path of the dependant library:
$ install_name_tool -change libfoo.dylib ../foo/libfoo.dylib a.out
so:
$ otool -L ./a.out
./a.out:
../foo/libfoo.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)
and the program can execute:
$ ./a.out
$ echo $?
6
Is there a clang option I can add to the command:
$ clang main.c -L../foo -lfoo
to avoid having to run:
$ install_name_tool -change libfoo.dylib ../foo/libfoo.dylib a.out
Note: I don't want to modify DYLD_LIBRARY_PATH
or such other environment variable.
?
See Question&Answers more detail:
os