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.
The -l option tells GCC to link in the specified library.
Linking is performed when the input file are object files " .o " (instead of source file " . cpp " or " . c "). GCC uses a separate linker program (called ld.exe ) to perform the linking.
When linking object files (static libraries) into an executable, the order in which you give the libraries matters. For simple scenarios where there are no cyclic references, the dependent library should come on the left, and the library which provides said dependency should come on the right.
GCC looks for headers requested with #include " file " first in the directory containing the current file, then in the directories as specified by -iquote options, then in the same places it would have looked for a header requested with angle brackets. For example, if /usr/include/sys/stat.
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.
Are you certain your configure script is paying attention to LDFLAGS? Run ./configure --help and see the options. There is usually one called something like --with-boost= and then you give the directory where boost is located. Try that one instead. Similarly for any other options you are having trouble with.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With