How to add include and lib paths to configure/make cycle?

229,508

Solution 1

You want a config.site file. Try:

$ mkdir -p ~/local/share
$ cat << EOF > ~/local/share/config.site
CPPFLAGS=-I$HOME/local/include
LDFLAGS=-L$HOME/local/lib
...
EOF

Whenever you invoke an autoconf generated configure script with --prefix=$HOME/local, the config.site will be read and all the assignments will be made for you. CPPFLAGS and LDFLAGS should be all you need, but you can make any other desired assignments as well (hence the ... in the sample above). Note that -I flags belong in CPPFLAGS and not in CFLAGS, as -I is intended for the pre-processor and not the compiler.

Solution 2

Set LDFLAGS and CFLAGS when you run make:

$ LDFLAGS="-L/home/me/local/lib" CFLAGS="-I/home/me/local/include" make

If you don't want to do that a gazillion times, export these in your .bashrc (or your shell equivalent). Also set LD_LIBRARY_PATH to include /home/me/local/lib:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/me/local/lib

Solution 3

This took a while to get right. I had this issue when cross-compiling in Ubuntu for an ARM target. I solved it with:

PATH=$PATH:/ccpath/bin CC=ccname-gcc AR=ccname-ar LD=ccname-ld CPPFLAGS="-nostdinc -I/ccrootfs/usr/include ..." LDFLAGS=-L/ccrootfs/usr/lib ./autogen.sh --build=`config.guess` --host=armv5tejl-unknown-linux-gnueabihf

Notice CFLAGS is not used with autogen.sh/configure, using it gave me the error: "configure: error: C compiler cannot create executables". In the build environment I was using an autogen.sh script was provided, if you don't have an autogen.sh script substitute ./autogen.sh with ./configure in the command above. I ran config.guess on the target system to get the --host parameter.

After successfully running autogen.sh/configure, compile with:

PATH=$PATH:/ccpath/bin CC=ccname-gcc AR=ccname-ar LD=ccname-ld CPPFLAGS="-nostdinc -I/ccrootfs/usr/include ..." LDFLAGS=-L/ccrootfs/usr/lib CFLAGS="-march=... -mcpu=... etc." make

The CFLAGS I chose to use were: "-march=armv5te -fno-tree-vectorize -mthumb-interwork -mcpu=arm926ej-s". It will take a while to get all of the include directories set up correctly: you might want some includes pointing to your cross-compiler and some pointing to your root file system includes, and there will likely be some conflicts.

I'm sure this is not the perfect answer. And I am still seeing some include directories pointing to / and not /ccrootfs in the Makefiles. Would love to know how to correct this. Hope this helps someone.

Share:
229,508
Lacrymology
Author by

Lacrymology

Professional game developer, a honest-to-god Code Warrior fighting the freaking Nintendo Wii

Updated on July 08, 2022

Comments

  • Lacrymology
    Lacrymology almost 2 years

    I need a place to install libraries in a linux box I have no su access to. I'm using ~/local[/bin,/lib,/include], but I don't know how can I tell ./configure to look for libraries there (particularly, I'm trying to compile emacs, which needs libgif, which doesn't come in my distro).

    I tried adding

    export PATH=$PATH:~/local/bin
    export LD_LIBRARY_PATH=~/local/lib
    export C_INCLUDE_PATH=~/local/include
    export CPLUS_INCLUDE_PATH=~/local/include
    

    to .bashrc but it doesn't seem to work.

    • Marc Plano-Lesay
      Marc Plano-Lesay over 12 years
      Note that excepted for the PATH, you overwrite your system default ones. If you make something like export C_INCLUDE_PATH=~/local/include:$C_INCLUDE_PATH, your compiler will search firstly in ~/local/include, and in $C_INCLUDE_PATH only if it didn't found the include in the first directory.
  • Lacrymology
    Lacrymology over 12 years
    when I add LDFLAGS and CFLAGS to .bashrc ./configure fails with a configure: error: C compiler cannot create executables...
  • long404
    long404 over 12 years
    They are probably overriding the configure test code compiler parameters. Just use the make env prefetching. Also try and see if configure doesn't already have an option for overriding libgif. If the autotools scripts are properly made it will alow you to spec a path where libgif is installed (e.g. override the default library location). That would be the cleaner solution.
  • Lacrymology
    Lacrymology over 12 years
    same difference.. tneme@ws16lab07:~/Descargas/emacs-23.3$ LDFLAGS="-L/home/tneme/local/lib" CFLAGS="-l/home/tneme/local/include" ./configure --prefix="/home/tneme/local" checking build system type... i686-pc-linux-gnu checking host system type... i686-pc-linux-gnu checking for gcc... gcc checking whether the C compiler works... no configure: error: in /home/tneme/Descargas/emacs-23.3': configure: error: C compiler cannot create executables See config.log' for more details t
  • long404
    long404 over 12 years
    these should be defined when you "make", not when you "configure".
  • long404
    long404 over 12 years
    just tried configuring emacs 23 with these and I didn't get that problem: LDFLAGS="-L/home/me/local/lib" CFLAGS="-I/home/me/local/include" ./configure checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking for gcc... gcc checking for C compiler default output file name... a.out checking whether the C compiler works... yes checking whether we are cross compiling... no checking for suffix of executables... checking for suffix of object files... o checking whether we are using the GNU C compiler... yes
  • long404
    long404 over 12 years
    so this works fine with configure as well on my system. What is your system/compiler/autotools version? I have Ubuntu 11.04.
  • long404
    long404 over 12 years
    If you still have C_INCLUDE_PATH CPLUS_INCLUDE_PATH defined try to remove them. I don't think the failed compile problem in configure is with CFLAGS/LDFLAGS. But still look at the generated "config.log" for details on the actual problem.
  • Brian Tiffin
    Brian Tiffin over 10 years
    William; A thanks, that was bang on advice about CPPFLAGS for building on a shared host. Saved much thrashing about with failed ./configure runs today, because of your note.