Error in compiling Boost thread example

Hi,
I am trying to compile the boost thread that I found here:
http://www-eleves-isia.cma.fr/documentation/BoostDoc/boost_1_29_0/libs/threa...
But i get the following error:
Can you please tell me what do i need to do to fix it?
./thread.o: In function `main':../thread.cpp:27: undefined reference
to `boost::thread::thread(boost::function0

i have more information about my problem:
I have add '-L/usr/lib' as my library path during linking and i make
sure i have 'libboost_thread*' library in '/usr/lib', but it still
does not work. Any idea why?
g++ -L/usr/lib -o"sandbox" ./thread.o
./thread.o: In function `__tcf_1':../thread.cpp:9: undefined reference
to `boost::mutex::~mutex()'
./thread.o: In function
`__static_initialization_and_destruction_0':../thread.cpp:9: undefined
reference to `boost::mutex::mutex()'
./thread.o: In function `main':../thread.cpp:90: undefined reference
to `boost::thread::thread(boost::function0
Hi,
I am trying to compile the boost thread that I found here: http://www-eleves-isia.cma.fr/documentation/BoostDoc/boost_1_29_0/libs/threa...
But i get the following error:
Can you please tell me what do i need to do to fix it?
./thread.o: In function `main':../thread.cpp:27: undefined reference to `boost::thread::thread(boost::function0
boost::function_base > const&)' :../thread.cpp:28: undefined reference to `boost::thread::join()' :../thread.cpp:28: undefined reference to `boost::thread::~thread()' :../thread.cpp:28: undefined reference to `boost::thread::~thread()' ./thread.o: In function `thread_alarm::operator()()':../thread.cpp:11: undefined reference to `boost::xtime_get(boost::xtime*, int)' :../thread.cpp:14: undefined reference to `boost::thread::sleep(boost::xtime const&)' collect2: ld returned 1 exit status make: *** [sandbox] Error 1 make: Target `all' not remade because of errors. Build complete for project sandbox

Meryl Silverburgh wrote:
i have more information about my problem:
I have add '-L/usr/lib' as my library path during linking and i make sure i have 'libboost_thread*' library in '/usr/lib', but it still does not work. Any idea why?
This is a compiler issue: you need to tell the compiler that you need to link to the thread lib with a -lboost_thread. John.

Thanks but if I specified '-L/usr/lib', won't it links all libraries
under '/usr/lib' which includes 'boost_thread'?
Thank you.
On 2/4/07, John Maddock
Meryl Silverburgh wrote:
i have more information about my problem:
I have add '-L/usr/lib' as my library path during linking and i make sure i have 'libboost_thread*' library in '/usr/lib', but it still does not work. Any idea why?
This is a compiler issue: you need to tell the compiler that you need to link to the thread lib with a -lboost_thread.
John.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Meryl Silverburgh wrote:
On 2/4/07, John Maddock
wrote: i have more information about my problem:
I have add '-L/usr/lib' as my library path during linking and i make sure i have 'libboost_thread*' library in '/usr/lib', but it still does not work. Any idea why? This is a compiler issue: you need to tell the compiler that you need to
Meryl Silverburgh wrote: link to the thread lib with a -lboost_thread.
John.
Thanks but if I specified '-L/usr/lib', won't it links all libraries under '/usr/lib' which includes 'boost_thread'?
Thank you.
No, that's not how linkers work. The notion of the search path (specified by -L) is separate from the choice of which libraries to search for. C++ does not have a fixed association from a particular header to a fixed library name (unless you use platform- specific extensions) -- you can specify the same search path, and still fulfill linkage requirements in many different ways by specifying different library names. In summary: -L says where to look for named libraries, and -l says which named libraries to look for. -- James

Thanks. i still have problem in linking boost thread library.
I have libboost_thread in /usr/lib:
$ ls -la libboost_thread*
-rwxr-xr-x 1 root root 68644 Feb 16 2006 libboost_thread.a*
lrwxrwxrwx 1 root root 25 Jan 5 16:03 libboost_thread.so ->
libboost_thread.so.1.33.1*
-rwxr-xr-x 1 root root 43236 Feb 16 2006 libboost_thread.so.1.33.1*
lrwxrwxrwx 1 root root 25 Jan 5 16:03 libboost_thread.so.2 ->
libboost_thread.so.1.33.1*
[meryl@localhost lib]$ pwd
/usr/lib
When i link it, i specified the -L and -l but I still get linker error:
g++ -L/usr/lib -o"sandbox" ./thread.o -llibboost_thread
/usr/bin/ld: cannot find -llibboost_thread
collect2: ld returned 1 exit status
make: *** [sandbox] Error 1
make: Target `all' not remade because of errors.
Build complete for project sandbox
Thanks for any help.
On 2/4/07, James Dennett
Meryl Silverburgh wrote:
On 2/4/07, John Maddock
wrote: i have more information about my problem:
I have add '-L/usr/lib' as my library path during linking and i make sure i have 'libboost_thread*' library in '/usr/lib', but it still does not work. Any idea why? This is a compiler issue: you need to tell the compiler that you need to
Meryl Silverburgh wrote: link to the thread lib with a -lboost_thread.
John.
Thanks but if I specified '-L/usr/lib', won't it links all libraries under '/usr/lib' which includes 'boost_thread'?
Thank you.
No, that's not how linkers work. The notion of the search path (specified by -L) is separate from the choice of which libraries to search for. C++ does not have a fixed association from a particular header to a fixed library name (unless you use platform- specific extensions) -- you can specify the same search path, and still fulfill linkage requirements in many different ways by specifying different library names.
In summary: -L says where to look for named libraries, and -l says which named libraries to look for.
-- James
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Meryl Silverburgh wrote:
Thanks. i still have problem in linking boost thread library.
I have libboost_thread in /usr/lib:
$ ls -la libboost_thread* -rwxr-xr-x 1 root root 68644 Feb 16 2006 libboost_thread.a* lrwxrwxrwx 1 root root 25 Jan 5 16:03 libboost_thread.so -> libboost_thread.so.1.33.1* -rwxr-xr-x 1 root root 43236 Feb 16 2006 libboost_thread.so.1.33.1* lrwxrwxrwx 1 root root 25 Jan 5 16:03 libboost_thread.so.2 -> libboost_thread.so.1.33.1* [meryl@localhost lib]$ pwd /usr/lib
When i link it, i specified the -L and -l but I still get linker error:
g++ -L/usr/lib -o"sandbox" ./thread.o -llibboost_thread /usr/bin/ld: cannot find -llibboost_thread collect2: ld returned 1 exit status make: *** [sandbox] Error 1 make: Target `all' not remade because of errors. Build complete for project sandbox
Thanks for any help.
Use -lboost_thread, not -llibboost_thread. The linker knows that library names start with "lib", and adds it on for you, just as it adds the extensions. -- James
participants (3)
-
James Dennett
-
John Maddock
-
Meryl Silverburgh