Linking boost::thread
Asked Answered
H

3

6

I'm trying to learn something with boost libraries, but I get a problem when I try to compile something that includes boost::threads. I get an error during linking, this is the message:

/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/../../../../x86_64-pc-linux-gnu/bin/ld: cannot find -lboost-thread

But it's strange because this happens only when I compile with a normal user, using root I can compile with no problem.

Thanks in advance.

Haha answered 5/3, 2012 at 19:25 Comment(3)
What was the command you ran? Usually you have to supply -L[/path/to/boost] somewhere in there so it knows where to find it.Dowd
Recent versions of boost would require to use "-lboost_thread"Acrospire
This is the command I ran: g++ -L/usr/local/boost_1_48_0/stage/lib -lboost-thread threadBoost.cpp, but it works only from rootHaha
P
1

check the lib name in boost install path (default: /usr/lib/), if it's libboost_thread.so, add -lboost_thread. Don't forget to specify the path to boost directory with -L/usr/lib/boost. If it only work as root, check your privilege in this directory :

ls -la /usr/lib/ | grep boost

you should see your login, and rw_r_r_ (check you have the read permission).

If you have this permission on the directory and on the boost lib, linking with gcc can be done :

g++ obj.o obj2.o -L/usr/lib -lboost_thread

if you don't own files or don't have read permissions, log as root and add them

chown -R /usr/lib <your login>
chmod +r /usr/lib/lib*.so
Pismire answered 6/3, 2012 at 8:42 Comment(1)
I've already checked permissions but there are 0k(777), I compile with this: g++ -L/usr/local/boost_1_48_0/stage/lib -lboost-thread threadBoost.cpp but still I get: cannot find -lboost-threadHaha
P
7

Include

#include <boost/thread/thread.hpp>

Other Linker Flags

-lboost_system -lboost_thread-mt
Pitre answered 11/10, 2015 at 17:5 Comment(0)
P
1

check the lib name in boost install path (default: /usr/lib/), if it's libboost_thread.so, add -lboost_thread. Don't forget to specify the path to boost directory with -L/usr/lib/boost. If it only work as root, check your privilege in this directory :

ls -la /usr/lib/ | grep boost

you should see your login, and rw_r_r_ (check you have the read permission).

If you have this permission on the directory and on the boost lib, linking with gcc can be done :

g++ obj.o obj2.o -L/usr/lib -lboost_thread

if you don't own files or don't have read permissions, log as root and add them

chown -R /usr/lib <your login>
chmod +r /usr/lib/lib*.so
Pismire answered 6/3, 2012 at 8:42 Comment(1)
I've already checked permissions but there are 0k(777), I compile with this: g++ -L/usr/local/boost_1_48_0/stage/lib -lboost-thread threadBoost.cpp but still I get: cannot find -lboost-threadHaha
F
0

Add /path/to/boost to your makefile Library Include path and your error will go away.

The other option is include boost it into your LIBPATH variable

Fiorin answered 5/3, 2012 at 22:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.