views:

3754

answers:

5

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.

+10  A: 

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.

Eric Petroelje
Thanks, thats along the lines I was thinking. However would it make sense to put that variable in external app_profile file and then source that file in the script? Or do you see any problems with that? I am thinking since multiple apps do need the same path it might make sense to externalize it?
Ville M
LD_LIBRARY_PATH (or LD_LIBRARY_PATH_32 and LD_LIBRARY_PATH_64) needs to be set before the executable is launched - because ld.so.1 reads it before you get to main() and doesn't reread it afterwards.
Jonathan Leffler
@Ville - I think that would work, but you'll want to try it out first to be sure
Eric Petroelje
@Jonathan - This would be before the executable is launched. You are setting the path in the script, then the script is launching the executable.
Eric Petroelje
+3  A: 

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.

Kenster
A: 

You can use the crle command:

crle -l /path/to/your/lib/file

Sedawk
crle suffers from the same problem as setting it in a global environment file - it affects all applications, so doesn't help when different applications need different versions of the libraries.
alanc
alanc is right.
Venkataramesh Kommoju
A: 

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.

Dan Ramaley
As noted in the comments on the previous crle answer, it's not the best solution, since it affects *all* programs, not just the broken ones that need a different path than they were built with. A shell script wrapper to set LD_LIBRARY_PATH just for those applications is much safer and saner than risking changes to all programs, and is the only way to deal with different applications needing incompatible paths.
alanc
A: 

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.

gengmao