Where to set LD_LIBRARY_PATH on Solaris?
Question
What is the best place to set up application specific LD_LIBRARY_PATH
variable on Solaris?
How does
LD_LIBRARY_PATH
variable work?
We currently set it up in .kshrc
, but different applications need different versions of messaging framework, but these applications run under the same use and hence they would need different LD_LIBRARY_PATH
, so in your opinion what is the best place to set this variable?
Basically I am trying to figure out how to make this variable path part of the application instead of user environment specific.
Solution
Usually I would just have a shell script that starts the application. In the shell script I would set LD_LIBRARY_PATH to whatever I need it to be for that app, then have the script start that app. Doing it that way should cause the path to be set only for that application.
OTHER TIPS
You can find a formal description of LD_LIBRARY_PATH
on the man page for "ld.so.1", ie run "man ld.so.1". It also describes some other variables that are honored by the runtime linker.
In addition to LD_LIBRARY_PATH
, executables and shared libraries can also have a built-in search path for libraries. If you are running an application that you have linked yourself, you can use ld's -R option to set the built in path (both Sun CC and gcc have options to do the same thing). This may allow you to avoid using LD_LIBRARY_PATH
in the first place.
Vladr, alanc is correct.
It's not recommended to set LD_LIBRARY_PATH on Solaris. At all.
If you need to bake a specific runpath into your library or executable, then you should use the -R flag to the linker. If building with gcc, then use -Wl,Rpath (I think).
If you need to do this for a post-build step (eg, because you're lacking source to recompile), then elfedit(1) will help you a lot. It's documented in the manpage, and also in the Linker+Libraries Guide at http://docs.oracle.com/cd/E26502_01/html/E26507/index.html
The crle response is most correct. On Solaris, LD_LIBRARY_PATH
shouldn't be used. Use crle instead. To view the current paths, just run "crle" by itself. To update the list, use crle -u -l /path/to/your/lib/directory
. The -u
is needed to write changes to the system configuration, otherwise the change will be temporary. See the man page for more options.
Just found a case that global LD_LIBRARY_PATH doesn't take effect, I had to wrap a script and set LD_LIBRARY_PATH before the app. crle is a good global solution if you installed a lot of libs under /opt/csw/lib, via pkgutil from blastwave.
You can check your .profile or .profile.user file.There will be be a commented entry for it .It's not recommended to be used since it's broken.You should build the binaries by passing values to flags rather than using the variable.
You can use the crle command:
crle -l /path/to/your/lib/file