67

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/
etc..

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

1 Answer 1

78

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/'
./configure

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/"

7
  • 7
    Maybe CPPFLAGS='-I/home/foo/sw/include:$CPPFLAGS' just in case something is out there ;)
    – Braiam
    Jan 5, 2014 at 12:59
  • 2
    Hi, Rinzwind. I am confused about the difference between LDFLAGS=-L and LIBS=-l. According to the help, they seems to be the same thing. Is there any difference?
    – user15964
    Mar 1, 2017 at 2:21
  • 1
    @user15964 -L refers to a directory to search for libraries while -l informs the linker to link against a specific library (to find which it will search the supplied -L directories alongside the default set.
    – sherrellbc
    Jun 4, 2019 at 16:58
  • Why is there a / after LDFLAGS but not after CPPFLAGS ? Is that a typo, or is it important?
    – vy32
    Jun 7, 2019 at 15:14
  • not perse, both work and no. The / at the end signifies it is a directory but it is not needed too include.
    – Rinzwind
    Jun 7, 2019 at 17:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .