In Linux Ubuntu I can compile C++ source code with dynamic library and tell the gcc compiler where to find the .so lib file by setting environment variable $LD_RUN_PATH before compile. I would like to know is there a equivalent method for clang compiler in OSX to do such run time dynamic library path search?
Thank you very much!
Edit:
The duplicate link given below is not what I want!
I would like to compile the search path for dylib into the executable. At runtime there should not be any path info set explicitly for $DYLD_LIBRARY_PATH environment path. Which is to say when you echo $DYLD_LIBRARY_PATH no path point to the dylib should be seen.
I achieved this by using
otool -L <executable>
to read the search path in my executable.
For any wrong or lack of search path, I use install_name_too to update or add the search path information.
For me I am changing my original linking path. I use
install_name_tool -change <old_path> <new_path> <executable>
for link path setting. After this I am able to run the executable correctly link to the dylib without setting anything inside $LD_LIBRARY_PATH or $LD_FALLBACK_LIBRARY_PATH.
When executing the compiled file at runtime there is still error on finding the lib path.
- Looks like your usage ofDYLD_LIBRARY_PATH
is wrong. Note, that variable should be set when you run your executable. – JerriDYLD_LIBRARY_PATH
variable. Actually, even with original wording your question is clearly not a duplicate. Sorry for inconvenience. Voted for reopen. – Jerri