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

6

110

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.

Foliate answered 26/9, 2011 at 21:25 Comment(1)
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.Fourdrinier
P
114

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.

Proptosis answered 1/10, 2011 at 8:33 Comment(1)
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.Laryngitis
S
44

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
Sunwise answered 26/9, 2011 at 21:29 Comment(7)
when I add LDFLAGS and CFLAGS to .bashrc ./configure fails with a configure: error: C compiler cannot create executables...Foliate
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.Sunwise
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 tFoliate
these should be defined when you "make", not when you "configure".Sunwise
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... yesSunwise
so this works fine with configure as well on my system. What is your system/compiler/autotools version? I have Ubuntu 11.04.Sunwise
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.Sunwise
E
9

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.

Eustacia answered 24/5, 2013 at 18:2 Comment(0)
B
1

To add to the other answers, sometimes you also have to set PKG_CONFIG_PATH

export PKG_CONFIG_PATH=~/local/lib/pkgconfig
Been answered 18/7, 2022 at 19:38 Comment(0)
J
0

for example, build git usig $HOME/curl


package=git
version=2.17.0

tarUrl=https://mirrors.edge.kernel.org/pub/software/scm/git/$package-$version.tar.gz
install(){
   ./configure --prefix=$HOME
   LDFLAGS="-L$HOME/lib" CFLAGS="-I$HOME/include" make -j 2
   make install
}
if [ -e $package-$version.tar.gz ]; then
   echo "cache"
else
   wget --no-check-certificate ${tarUrl}
   tar -xvf $package-$version.tar.gz
fi
cd ./$package-$version
install
Jodeejodhpur answered 18/2, 2022 at 2:56 Comment(0)
T
0

To change environment only for current command from Carl Norum's suggestion:
   LDFLAGS+="-L<directory>" CFLAGS+="-I<directory>" make ("make" command should be at the end)

   For example:
     LDFLAGS+="-L/usr/lib" CFLAGS+="-I/usr/include/gstreamer-1.0 -I/usr/include/opencv4 -I/opt/nvidia/deepstream/deepstream-6.1/sources/includes" make

Toots answered 18/2, 2023 at 5:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.