Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Symbol lookup error in shared library when accessing boost bind

I am trying to add multithreading into my library, so I am working on creating a thread executor for my library. For this I am using boost threads.

This is the error I am getting when running a test case that links to the library:

symbol lookup error: libmylibexample.so.0: undefined symbol: _ZTVN5boost6detail16thread_data_baseE

This is the line of code in my shared library that is causing the error:

MyNameSpace::Producer producer = MyNameSpace::Producer();
threads.create_thread(boost::bind(&MyNameSpace::Producer::run, &producer));

I am compiling the library using autotools and libtool. The code compiles fine. I then create a test case that I am trying to reference the library. Here is the compilation order for compiling the test case:

g++ -I.  -I../include -g -O2 -MT runTest-runTest.o -MD -MP -MF .deps/runTest-runTest.Tpo -c -o runTest-runTest.o `test -f 'runTest.cc' || echo './'`runTest.cc

and this is my linking stage:

mv -f .deps/runTest-runTest.Tpo     .deps/runTest-runTest.Po

/bin/bash ../libtool --tag=CXX   --mode=link g++  -g -O2 ../libmylibexample/libmylibexample.la   -o runTest runTest-runTest.o -lboost_system -lboost_filesystem -lboost_regex -lboost_thread-mt -lfftw3 -ltiff

libtool: link: g++ -g -O2 -o .libs/runTest runTest-runTest.o  ../libmylibexample/.libs/libmylibexample.so -lboost_system -lboost_filesystem -lboost_regex -lboost_thread-mt -lfftw3 /usr/lib/x86_64-linux-gnu/libtiff.so

One of my colleagues suggested initializing some boost templates relating to threading to help the shared library to load the symbol from the boost_thread library. I am not entirely certain the best method to do this and if this it the right way of making things get loaded.

So to wrap things up: The error appears to involve not being able to load a symbol defined in libboost_thread from my shared library.

like image 325
Jameshobbs Avatar asked Jan 27 '14 19:01

Jameshobbs


1 Answers

As the error indicates, you need to link libmylibexample with libboost_thread.

like image 81
ldav1s Avatar answered Oct 22 '22 06:10

ldav1s