Ubuntu – How to add libraries path to the ./configure command


I would like ./configure to link to a library and some include files. My library is stored in /home/foo/sw/lib/ and my files are stored in /home/foo/sw/include.

./configure --help throws out the following:

Some influential environment variables:

  CC           C compiler command
  CFLAGS       C compiler flags
  LDFLAGS      linker flags, e.g. -L<lib dir> if you have libraries in a 
               nonstandard directory <lib dir>
  LIBS         libraries to pass to the linker, e.g. -l<library>
  CPPFLAGS     (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if 
               you have headers in a nonstandard directory <include dir>
  CPP          C preprocessor

I have tried various combinations:

./configure --prefix=/home/foo/sw -I</home/foo/sw/include> -L</home/foo/sw/lib/>
./configure --prefix=/home/foo/sw -I=/home/foo/sw/include -L=/home/foo/sw/lib/
./configure --prefix=/home/foo/sw -I/home/foo/sw/include -L/home/foo/sw/lib/

But I can't seem to get the syntax right. If anyone can help me out, that would be greatly appreciated. THANKS!

Best Answer

You missed the meaning of

Some influential environment variables:

So you set them as an environment variable; configure determines LDFLAGS and CPPFLAGS by checking config files and the environment. You can set them like this ...

export CPPFLAGS='-I/home/foo/sw/include/'
export LDFLAGS='-L/home/foo/sw/lib/'

or as a one-liner:

env CPPFLAGS='-I/home/foo/sw/include/' LDFLAGS='-L/home/foo/sw/lib/' ./configure

Please note that it is possible that you cannot use subdirectories under /home/foo/sw/lib/

f.e. putting your library in /home/foo/sw/lib/bar/ might show you a lib not founderror.

However you can use multiple entries:

LDFLAGS="-L/home/foo/sw/lib/ -L/home/foo/bar/lib/"

Related Question