c++ – libpthread.so.0: error adding symbols: DSO missing from command line

Question:

I am trying to use message_queue . The code itself does nothing except call the constructor. The build log :

/ usr / bin / ld: obj / Debug / main.o: undefined symbol reference "pthread_condattr_setpshared @@ GLIBC_2.2.5" //lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status

using namespace boost::interprocess;

int main()
{ 
    message_queue(open_or_create,"message_queue" ,100 ,100);
}

What's happening?

Answer:

… / libpthread.so.0: error adding symbols: DSO missing from command line

here it is advised to add an option

-lpthread

to the compiler options.


in order to compile your example, I had to add on the first line:

#include <boost/interprocess/ipc/message_queue.hpp>

and pass the -lrt -lpthread options to the compiler. then the test program from the test.cpp file compiles successfully:

$ CPPFLAGS="-lrt -lpthread" make test
g++  -lrt -lpthread   test.cpp   -o test

the error you described is easily reproducible by removing the -lpthread option:

$ CPPFLAGS="-lrt" make test
g++  -lrt   test.cpp   -o test
/usr/bin/ld: /tmp/cc8fR82D.o: undefined reference to symbol 'pthread_condattr_setpshared@@GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
<builtin>: recipe for target 'test' failed
make: *** [test] Error 1
Scroll to Top