views:

113

answers:

4

I'm trying to compile a piece of software which has the standard build process e.g.

configure
make
make install

The software requires a library e.g. libreq.so which is installed in /usr/local/lib. However, my problem is I'd like to build the software and link it with a different version of the same library (i have the source for the library as well) that I've installed in /home/user/mylibs.

My question is, how do I compile and link the software against the library in /home/user/mylibs rather than the one in /usr/local/lib

I tried setting "LD_LIBRARY_PATH" to include /home/user/mylibs but that didn't work.

Thanks!

+2  A: 

Try using LD_PRELOAD set to your actual file.

unwind
Thanks, but that doesn't seem to override the /usr/local/lib version in the build process, are there some arguments I can pass to configure to tell it to use a library in a specific location?
JS
+4  A: 

When you have an autoconf configure script, use:

CPPFLAGS=-I/home/user/include LDFLAGS=-L/home/user/mylibs ./configure ...

This adds the nominated directory to the list of directories searched for headers (usually necessary when you're using a library), and adds the other nominated directory to the list searched for actual libraries.

I use this all the time - on my work machine, /usr/local is 'maintained' by MIS and contains obsolete code 99.9% of the time (and is NFS-mounted, read-only), so I struggle to avoid using it at all and maintain my own, more nearly current, versions of the software under /usr/gnu. It works for me.

Jonathan Leffler
Yes that seems to work, thanks very much!
JS
A: 

LD_LIBRARY_PATH is for finding the dynamic link libraries at runtime. At compiling you should add -L parameters to gcc/g++ to specify in which directory the *.so files are. You also need to add the library name with -l<NAME> (where the library is libNAME.so).

Important! For linking you not only need the libNAME.so file but a libNAME.a is needed too.

When you run the application, don't forget to add the dir to the LD_LIBRARY_PATH.

Vereb
@ Important! For linking you not only need the libNAME.so file but a libNAME.a is needed too. -> aren't you talking about windows (.dll + .lib)? .a is static library and isn't needed at all.
Yossarian
You must be right! I thought it is needed under Linux too.
Vereb
A: 

When you added the /home/user/mylibs to the LD_LIBRARY_PATH did you add it to the front or end of the existing paths? The tokens are searched in-order so you will want yours to appear first in the list.

Also, many standard build environments that use configure will allow you to specify an exact library for each required piece. You will have to run ./configure --help but you should see something like --using-BLAH-lib=/path/to/your/library or similar.

ezpz