sof
sof

Reputation: 9649

Failed to build app using libboost_thread

I followed get started to build and install boost 1.61.0 to mypath-to-boost, then tried to use libboost_thread below,

// mythread.cpp

#include <boost/thread.hpp>

void a_thread() {}

int main() {
  boost::thread t{a_thread};
}

building mythread.cpp,

$ g++ mythread.cpp -std=c++11 -Imypath-to-boost -lboost_thread -Lmypath-to-boost/lib

then got errors,

/usr/bin/ld: warning: libboost_system.so.1.61.0, needed by mypath-to-boost/lib/libboost_thread.so, not found (try using -rpath or -rpath-link)
mythread.cpp: undefined reference to `boost::system::generic_category()'
...

checking libboost_thread,

$ ls -l mypath-to-boost/lib/*thread*

then found the libs,

libboost_thread.a
libboost_thread.so -> libboost_thread.so.1.61.0
libboost_thread.so.1.61.0

So what's the problem to cause the build failure?

Upvotes: 0

Views: 1266

Answers (1)

Nim
Nim

Reputation: 33655

You need to add boost_system library to link line...

Upvotes: 1

Related Questions