views:

224

answers:

3

I work on a Fedora Linux box.

I have a whole host of binaries and libraries that I've installed locally under my home directory.

I'd like to set my system up so installing software there functions the same way (for me) as if the root user installed it without a prefix.

I can run binaries installed in ~/local/bin just fine by adding that dir to my PATH variable, but what about linking to libraries in ~/local/lib and ~/local/lib64?

Is there something akin to LD_LIBRARY_PATH variable but to find the library at compile rather than runtime? I don't want to worry about explicitly passing the path to the compiler via L~/local/lib or through flags in the ./configure script.

A: 

Set the LIBRARY_PATH environment variable to $HOME/local/lib:$HOME/local/lib64. You can also set the environment variables C_INCLUDE_PATH and CPLUS_INCLUDE_PATH to find include files in $HOME/local/include. These are environment variables used by GCC to find libraries and include files, so they probably won't work with other compilers.

mipadi
Did you mean LD_LIBRARY_PATH?
Jonathan Leffler
No. LD_LIBRARY_PATH is for loading libraries; LIBRARY_PATH is used by GCC to find them.
mipadi
A: 

As well as setting LD_LIBRARY_PATH, you can also look at /etc/ld.so.conf (which works for all users, even root). Also consider the security of your system if you use /etc/ld.so.conf; if people run the library from your directory, they are trusting you not to mess with them.

Jonathan Leffler
+1  A: 

There's two ways to get the libraries to work at runtime:

  1. If the libraries are just for your use, and it's not a multi-user system, then use the $LD_LIBRARY_PATH environment variable

  2. If you're the only user on the system you could add your directories into /etc/ld.so.conf, or into a new text file in /etc/ld.so.conf.d. Run ldconfig afterwards to rebuild the system's shared library cache

At compile time things aren't so clear. The GNU linker supports the -rpath parameter and the $LD_RUN_PATH environment variable to specify library paths. However in each case the result path ends up hard-coded in the binary, so if you subsequently want to move your files you'd have to recompile them.

I believe that programs built using ./configure style scripts should be able to find any libraries that are in your $LD_RUN_PATH, but haven't been able to test that.

In either event, running ./configure --prefix=${HOME}/local should allow configure to resolve both the include directories and the libraries.

Alnitak