109

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.

1
  • 4
    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. Sep 26, 2011 at 21:32

6 Answers 6

110

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.

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. Oct 2, 2013 at 9:31
43

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
7
  • 1
    when I add LDFLAGS and CFLAGS to .bashrc ./configure fails with a configure: error: C compiler cannot create executables... Sep 26, 2011 at 22:05
  • 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.
    – long404
    Sep 26, 2011 at 22:08
  • 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 Sep 26, 2011 at 22:33
  • these should be defined when you "make", not when you "configure".
    – long404
    Sep 27, 2011 at 5:14
  • 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
    Sep 27, 2011 at 5:26
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.

1

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

export PKG_CONFIG_PATH=~/local/lib/pkgconfig
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
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

0

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.