I have two versions of GCC installed on my system 4.6.2 and 4.7.0. I am running Fedora Core 16.
4.6.2 is installed in /usr/bin
and 4.7.0 is installed in /home/nerozehl/local/bin
. The libraries and runtime for C++ are also compiled and installed in /home/nerozehl/local/lib
and /home/nerozehl/local/lib64
.
I also have two versions of Boost installed, with libraries in /usr/lib64
and /home/nerozehl/local/lib
. (Boost 1.47.0 and 1.49.0, respectively)
The problem I am having is that g++ / ld are linking against the default libraries, and not the newer ones in /home/nerozehl/local
. I am using configure
to generate Makefiles, and am calling it this way:
CXX=g++47 CXXFLAGS="-g -O0 -pg" LDFLAGS="-L/home/nerozehl/local/lib" ./configure --prefix=/home/nerozehl/local
Where g++47
resides in the /home/nerozehl/local/bin
(in my $PATH
).
When I compile, everything is fine, and the newer headers are used, but when I check what it was linked against:
ldd source/noes
linux-vdso.so.1 => (0x00007fffebfff000)
libboost_filesystem-mt.so.1.47.0 => /usr/lib64/libboost_filesystem-mt.so.1.47.0 (0x0000003c6a800000)
libboost_system-mt.so.1.47.0 => /usr/lib64/libboost_system-mt.so.1.47.0 (0x0000003c6a400000)
libboost_program_options-mt.so.1.47.0 => /usr/lib64/libboost_program_options-mt.so.1.47.0 (0x0000003c6ac00000)
libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x0000003c6dc00000)
libm.so.6 => /lib64/libm.so.6 (0x0000003c68c00000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x0000003c69c00000)
libc.so.6 => /lib64/libc.so.6 (0x0000003c68800000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003c69000000)
librt.so.1 => /lib64/librt.so.1 (0x0000003c69800000)
/lib64/ld-linux-x86-64.so.2 (0x0000003c68400000)
For the life of me I can't figure out how to force g++ / ld / configure to use my newer libraries. Any help would be appreciated.
ldd doesn't tell you what the executable was linked against -- it tells you what shared objects the executable will load when it's run. If you want it to load from /home/nerozehl when it runs, you need to do one of several things:
set LD_LIBRARY_PATH
to contain /home/nerozehl/local/lib when you run the program
add /home/nerozehl/local/lib to ld.so.conf so it will get used by everyone. Only works on systems (such as linux) that use ld.so.conf, however.
link the program with -Wl,-rpath,/home/nerozehl/local/lib
. Only works on systems that use ELF or another executable format that supports it, however. It also hardcodes the path into the executable, which is somewhat fragile -- if you move the executable to another machine or rearrange your filesystem it may break.