Use of LD_LIBRARY_PATH

Ξ May 10th, 2009 | → | ∇ Development |

The use of Linux environment variables is not new for me, but for special reasons I learned something new about one specific environment variable. You’ve guessed it, although the variable itself was not new to me, I’m now more certain about the uses of LD_LIBRARY_PATH.

The motivation for this post is, at least to some degree, a linkage problem that I had to solve this week.
The only difference between two development ’sandboxes’ was the definition of LD_LIBRARY_PATH.  I was certain that the variable was only used during execution time (to configure the search path for installed shared libraries). I was wrong!

After almost two hours banging my head against the wall, I found a very interesting paragraph in ld’s manual page.


[...]

The linker uses the following search paths to locate required shared libraries:

[...]

5. For a native linker, the search the contents of the environment variable "LD_LIBRARY_PATH".

[...]

So, the LD_LIBRARY_PATH is used to by the linker!

This solved my very specific problem, but I agree with the opinion of those [1][2][3] who defend that LD_LIBRARY_PATH should not be used to configure the linking process. In a development environment, the libraries to be used by the linker should be configured using the -l and -L flags. In this case, and only in this case, should the LD_LIBRARY_PATH be used to add development libraries to loading path.

 

Leave a reply


On the nightstand...


    The Art of Agile Development


    Beautiful Architecture


    Modern C++ Design


    Large Scale C++ Software Design

Personal

Friends


Interesting


Shared Readings