Rafael S. Calsaverini
Rafael S. Calsaverini

Reputation: 14012

Linux/gcc - How should I compile my programs to use libraries installed in my home directory?

I never programmed in a computer without access to install libraries as root so I'm not really sure of what should I do to use libraries that I do not install in the usual places.

Usually, when I have admin priviledges I'd do the usual:

./configure 
make 
make install

to install the library. Then I'd do the common #include <library> and compile with (actually this is done in my makefile):

gcc -c file1.c
   gcc -c file2.c
   ...
   gcc file1.o file2.o ... -o executable -llibrary 

How should I deal with a library that was installed in my home folder? Suppose I install it with:

./configure --prefix=$HOME
make 
make install

And now I have directories like $HOME/include, $HOME/lib and $HOME/share, etc... how should I include the lib, compile and link the binaries?

Upvotes: 1

Views: 807

Answers (1)

fvu
fvu

Reputation: 32953

Just add

-L/home/yours/subdirforlibs

to the linker's command line to instruct it to look in that directory for libraries.

The directory options for gcc are explained here

Upvotes: 3

Related Questions