This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Confused about linking
- From: Mattias Brändström <thebrasse at brasse dot org>
- To: gcc-help at gcc dot gnu dot org
- Date: Mon, 09 Aug 2004 17:29:07 +0200
- Subject: Confused about linking
Hello!
I am seriously confused when it comes to linking my executable written
in C++. More specificaly I want to link againts boost_thread and
boost_regex on a Fedora 2 system.
These files are located in /usr/lib:
/usr/lib/libboost_thread.so.1
/usr/lib/libboost_thread.so.1.31.0
/usr/lib/libboost_regex.a
/usr/lib/libboost_regex.so.1.31.0
/usr/lib/libboost_regex.so.1
I have a small file named 'foo.cpp' containing the following:
int main()
{
return 0;
}
When I try the following:
g++ foo.cpp -L/usr/lib -lboost_regex
everthing works fine. But when I do this:
g++ foo.cpp -L/usr/lib -lboost_thread
I get:
/usr/bin/ld: cannot find -lboost_thread
collect2: ld returned 1 exit status
When removing /usr/lib/libboost_regex.a I get the same error as above
when trying to 'g++ foo.cpp -L/usr/lib -lboost_regex'.
I was under the impression that g++ would look for shared librarires and
try to link againt them first and if that didn't work try to link againt
static libraries. Perhaps this is not tha case? Can someone enlighten me
on this, probalbly trivial, issue?
Thanks in advance!
:.:: mattias
PS.
> g++ -v foo.cpp -L/usr/lib -lboost_thread
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.3.3/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --disable-libunwind-exceptions --with-system-zlib
--enable-__cxa_atexit --host=i386-redhat-linux
Thread model: posix
gcc version 3.3.3 20040412 (Red Hat Linux 3.3.3-7)
/usr/lib/gcc-lib/i386-redhat-linux/3.3.3/cc1plus -quiet -v
-D__GNUC__=3 -D__GNUC_MINOR__=3 -D__GNUC_PATCHLEVEL__=3 -D_GNU_SOURCE
foo.cpp -D__GNUG__=3 -quiet -dumpbase foo.cpp -auxbase foo -version -o
/tmp/cccCYtHd.s
GNU C++ version 3.3.3 20040412 (Red Hat Linux 3.3.3-7) (i386-redhat-linux)
compiled by GNU C version 3.3.3 20040412 (Red Hat Linux 3.3.3-7).
GGC heuristics: --param ggc-min-expand=64 --param ggc-min-heapsize=64549
ignoring nonexistent directory "/usr/i386-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/3.3.3
/usr/include/c++/3.3.3/i386-redhat-linux
/usr/include/c++/3.3.3/backward
/usr/local/include
/usr/lib/gcc-lib/i386-redhat-linux/3.3.3/include
/usr/include
End of search list.
as -V -Qy -o /tmp/ccqqpjhi.o /tmp/cccCYtHd.s
GNU assembler version 2.15.90.0.3 (i386-redhat-linux) using BFD version
2.15.90.0.3 20040415
/usr/lib/gcc-lib/i386-redhat-linux/3.3.3/collect2 --eh-frame-hdr -m
elf_i386 -dynamic-linker /lib/ld-linux.so.2
/usr/lib/gcc-lib/i386-redhat-linux/3.3.3/../../../crt1.o
/usr/lib/gcc-lib/i386-redhat-linux/3.3.3/../../../crti.o
/usr/lib/gcc-lib/i386-redhat-linux/3.3.3/crtbegin.o -L/usr/lib
-L/usr/lib/gcc-lib/i386-redhat-linux/3.3.3
-L/usr/lib/gcc-lib/i386-redhat-linux/3.3.3/../../.. /tmp/ccqqpjhi.o
-lboost_thread -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc
/usr/lib/gcc-lib/i386-redhat-linux/3.3.3/crtend.o
/usr/lib/gcc-lib/i386-redhat-linux/3.3.3/../../../crtn.o
/usr/bin/ld: cannot find -lboost_thread
collect2: ld returned 1 exit status