This is how I understand LD_LIBRARY_PATH works:Linking of programs during compilation is done by the linker ('ld').Loading of shared libraries at runtime is done by the loader ('/lib/ld-linux.so.2').Note: '/lib/ld-linux.so.2' is typically a symlink to'/lib/ld-[glibc_version].so'.e.g. '/lib/ld-linux.so.2' -> '/lib/ld-2.3.2.so' (DSL uses glibc 2.3.2.)(1) For example: We have an application called 'my_program' that needs some libraries in '/opt/compile-3.3.5/lib/'. We can add LD_LIBRARY_PATH to the environment, and then run the application:

Code Sample

export LD_LIBRARY_PATH=/opt/compile-3.3.5/libmy_program

Or, we can add LD_LIBRARY_PATH to the command line; it will take effect only for this command; it does not persist in the environment:

Code Sample

LD_LIBRARY_PATH=/opt/compile-3.3.5/lib my_program

or

Code Sample

my_program LD_LIBRARY_PATH=/opt/compile-3.3.5/lib

(3) Another method, that does not involve LD_LIBRARY_PATH, is to add '/opt/compile-3.3.5/lib/' to the ld.so cache file ('/etc/ld.so.cache'):

Code Sample

# Edit /etc/ld.so.conf:editor /etc/ld.so.conf# Run 'ldconfig' to rebuild '/etc/ld.so.cache' using the directories specified in '/etc/ld.so.conf':ldconfig# Run application:my_program

Note: 'ldconfig' does not make use of LD_LIBRARY_PATH.To test this, we could do the following, for example:

Code Sample

export LD_LIBRARY_PATH=/opt/compile-3.3.5/libldconfig# Then unset LD_LIBRARY_PATH:unset LD_LIBRARY_PATH# Then run the application:my_program(You will get an error.)

As this shows, in line 2, 'ldconfig' does NOT add '/whatever/' to '/etc/ld.so.cache'.Thus, once we unset LD_LIBRARY_PATH in line 4, the library in '/whatever/' can no longer be found.Conclusion: The only way to add a directory to '/etc/ld.so.cache' is to edit '/etc/ld.so.conf'.

Re: Linking'ld' can use LD_LIBRARY_PATH to find libraries at link-time (such as '-liconv') in the same fashion as above.(1) We can export LD_LIBRARY_PATH before running 'configure':

Code Sample

export LD_LIBRARY_PATH=/opt/compile-3.3.5/lib./configuremake

LD_LIBRARY_PATH must not be unset until compilation is finished; otherwise, linking errors will occur because the linker cannot find needed libraries.(1) Or, we can specify LDFLAGS when running 'configure':

Code Sample

LDFLAGS=-L/opt/compile-3.3.5/lib ./configure

We don't need to use LD_LIBRARY_PATH if we use LDFLAGS (but I am not sure about this...).