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.

ildjarn
  • 62,044
  • 9
  • 127
  • 211
alkz
  • 337
  • 2
  • 7
  • 17
  • 1
    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. – Michael Kristofik Mar 05 '12 at 20:57
  • Recent versions of boost would require to use "-lboost_thread" – dsign Mar 05 '12 at 21:19
  • 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 root – alkz Mar 05 '12 at 23:12

3 Answers3

7

Include

#include <boost/thread/thread.hpp>

Other Linker Flags

-lboost_system -lboost_thread-mt
neoneye
  • 50,398
  • 25
  • 166
  • 151
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
blaize
  • 119
  • 4
  • 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-thread – alkz Mar 06 '12 at 12:28
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

Oliver
  • 928
  • 9
  • 25