-   Programming (
-   -   How to (temporarily) add a library search path? (

G00fy 06-24-2007 02:11 AM

How to (temporarily) add a library search path?
I try to execute a program. It gives me this "cannot open shared object file: No such file or directory" error...

I know I can add it to and run ldconfig. But that's not what I want... For example on windows you can just copy the responsible "dll" to the executable directory and it works as well.

But how can I achieve the same in Linux? I tried already making a softlink with the same name to the executable directory, but that didn't work...

Anyone knows :)?


b0uncer 06-24-2007 05:16 AM

Maybe create the softlink into a directory that is always checked for libs, like /usr/lib for example? Or define the library variable manually with export.. (note: I don't remember what it's exactly called, check using console).

G00fy 06-24-2007 05:21 AM

Sorry :) I found it while googling.

For someones reference:

LD_LIBRARY_PATH=/your/dir <executable>

in my case it was:
me@mydesktop:/var/tmp/my_program$ LD_LIBRARY_PATH=/var/tmp/my_libs ./my_program

ta0kira 07-03-2007 07:59 AM

If you are the developer of the program, use -rpath-link path and -rpath path when linking. -rpath-link provides a search path for link resolution to make sure you have a good link, but does nothing for run-time. When you use -rpath, that adds a path to the binary so that at run-time ld will search that path for dependent libraries.

ta0kira 07-03-2007 08:06 AM

Example: program needs library which is located at ../lib from the build directory, and after installation it will be located in the same path as program. You would use -rpath-link ../lib -rpath . when linking program to

All times are GMT -5. The time now is 01:07 PM.