tags:

views:

191

answers:

3
+2  Q: 

LD_LIBRARY_PATH

Can I set LD_LIBRARY_PATH for an individual application? I am looking into system call failure, so is there any way I can set set the correct path using the LD_LIBRARY_PATH setting?

+7  A: 

Simplest way would be to create a shell script.

Have the shell script export your new LD_LIBRARY_PATH variable then launch your application

e.g. (where foo is your app)

#!/bin/sh
LD_LIBRARY_PATH=some_path:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
foo
Glen
+6  A: 

As simple as:

LD_LIBRARY_PATH=new_path:$LD_LIBRARY_PATH foo

which works in bash. I think it works in all bourne shell derivatives, but I can't guarantee it.

Of course, with this approach, you have to type the path every time. To do it repeatedly, prefer Glen's approach.

dmckee
The technique works in Bourne shell, Korn shell, and POSIX shells.
Jonathan Leffler
+3  A: 

One item to be aware of: you cannot set LD_LIBRARY_PATH within a program and make it have any effect on the current program. This is because the dynamic loader (ld.so.1 or some similar name) is already loaded and has read and processed the environment variable before any of your code is run. You can set it in the current process's environment, and that value will then affect any child processes, and you could use one of the exec() family of functions to run a program with the environment set. In an extreme case, you could re-execute the current program - but that is extreme!

Jonathan Leffler