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.
Boost. Thread is the library that allows you to use threads. Furthermore, it provides classes to synchronize access on data which is shared by multiple threads. Threads have been supported by the standard library since C++11.
Boost. DateTime: This dependency is mandatory, but even if Boost. DateTime is a non header-only library Boost. Thread uses only parts that are header-only, so in principle you should not need to link with the library.
Boost. Sync supports building against one of the following underlying APIs: pthreads or Windows API. On most platforms pthreads are the only option. On Windows, Windows API is used by default, but pthreads can be enabled.
Include
#include <boost/thread/thread.hpp>
Other Linker Flags
-lboost_system -lboost_thread-mt
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With