Search code examples
c++boostlinkerboost-thread

Linking boost::thread


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.


Solution

  • 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