Can I specify where g++looks for libs at runtime?

Dr. David Kirkby david.kirkby@onetel.net
Mon Jun 29 13:29:00 GMT 2009


I've built gcc 4.4.0 on SPARC having my gmp and mpfr in /usr/local/lib.

This is now I built it

LD_OPTIONS='-L/usr/local/lib -R/usr/local/lib'
export LD_OPTIONS
rm -rf gcc-4.4.0-built-with-gcc-3.4.3-ABI32d
mkdir gcc-4.4.0-built-with-gcc-3.4.3-ABI32d

cd gcc-4.4.0-built-with-gcc-3.4.3-ABI32d
/home/kirkby/gcc-4.4.0/configure 'CC=/usr/sfw/bin/gcc' \
--prefix=/usr/local/gcc-4.4.0-sun-linker \
--without-gnu-as \
--without-gnu-ld \
--with-as=/usr/ccs/bin/as  \
--with-ld=/usr/ccs/bin/ld \
--enable-languages=c,c++,fortran \
--with-mpfr-lib=/usr/local/lib \
--with-mpfr-include=/usr/local/include \
--with-gmp-include=/usr/local/include \
--with-gmp-lib=/usr/local/lib \
--with-libiconv-prefix=/usr/lib/iconv
/usr/sfw/bin/gmake -j 20


I find the C compiler works ok. But the C++ compiler can't find its own 
library files.

kirkby@t2:[~] $ gcc hello_world.c
kirkby@t2:[~] $ ./a.out
hello world
kirkby@t2:[~] $ g++ test.cpp
kirkby@t2:[~] $ ./a.out
ld.so.1: a.out: fatal: libstdc++.so.6: open failed: No such file or 
directory
Killed

I'm using the Sun linker, not the GNU one, so it's possible g++ is 
sending stuff to the linker to indicate where the libraries are, but the 
linker is ignoring them.

Ideally I'd like to send something to the Sun linker to day "look in 
/usr/local/gcc-4.4.0-sun-linker/lib for libraries too"

If I set LD_LIBRARY_PATH, then this will work.

kirkby@t2:[~] $ LD_LIBRARY_PATH=/usr/local/gcc-4.4.0-sun-linker/lib
kirkby@t2:[~] $ export LD_LIBRARY_PATH
kirkby@t2:[~] $ g++ test.cpp
kirkby@t2:[~] $ ./a.out
Hello World






More information about the Gcc-help mailing list