kevinkreiser/prime_server

-lpthread not linked against

Closed this issue · 5 comments

in some systems autotools doesnt throw -lpthread in there and you end up getting link errors. @ptpt describes this here: #35

hopefully there is a way to automatically link against pthreads via autotools detection mechanisms. it would be a shame to have to hardcode that

ptpt commented

This issue emerges in the latest Ubuntu 16.04, as well as my Arch Linux. It also affects building of Valhalla libraries which depends on pthread. Time to fix it.

Here I set up a minimal example, and tested it on Ubuntu 14.04, 16.04 and my Arch Linux. No one complains any more.
https://gist.github.com/ptpt/29727214caa1890db647e024bf4e4d88

Basically it uses this M4 macro https://www.gnu.org/software/autoconf-archive/ax_pthread.html which added the neccessary flags to make compiler and linker happy. It also sets CC to the special PTHREAD_CC (see the macro file for explanation).

I think it might be a robust way to solve the issue.

i dont understand, i build prime_server packages right now on xenial without any extra work for pthreads:

https://launchpad.net/~kevinkreiser/+archive/ubuntu/prime-server

m4 macros to get the pthread flags is fine but i dont understand how you dont get it for free since std::thread uses pthreads on gcc. at any rate, we can just do this and close the issue.

ptpt commented

Indeed @kevinkreiser this seems to be an issue with libtool which determines whether adding -pthread or not during linking. Sometimes it does it right, sometime wrong. Below are some examples

On Ubuntu 16.04, make prime_echod added -pthread, good:

$ ./libtool --tag=CXX   --mode=link g++ -Iprime_server -g -O2 -std=c++11   -o prime_echod src/prime_echod-prime_echod.o -lzmq -lcurl libprime_server.la
libtool: link: g++ -Iprime_server -g -O2 -std=c++11 -o .libs/prime_echod src/prime_echod-prime_echod.o  ./.libs/libprime_server.so -lzmq /usr/lib/x86_64-linux-gnu/libcurl.so -pthread

On Arch Linux, make prime_echod failed to add it:

$ ./libtool --tag=CXX   --mode=link g++ -Iprime_server -g -O2 -std=c++11   -o prime_echod src/prime_echod-prime_echod.o -lzmq -lcurl libprime_server.la
libtool: link: g++ -Iprime_server -g -O2 -std=c++11 -o .libs/prime_echod src/prime_echod-prime_echod.o  ./.libs/libprime_server.so -lzmq -lcurl -Wl,-rpath -Wl,/usr/local/lib
/usr/bin/ld: src/prime_echod-prime_echod.o: undefined reference to symbol 'pthread_create@@GLIBC_2.2.5'
/usr/lib/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

However, when I compile loki on Ubuntu 16.04, it failed to add -pthread in the step of make test/loki_service:

$ ./libtool --tag=CXX   --mode=link g++ -Ivalhalla  -g -O2 -std=c++11 -L/usr/lib/x86_64-linux-gnu   -o test/loki_service test/test_loki_service-loki_service.o test/test_loki_service-test.o -lprime_server -L/usr/local/lib -lvalhalla_midgard -lvalhalla_baldr -lvalhalla_sif -L/usr/lib/x86_64-linux-gnu -lboost_program_options  -lboost_system -lboost_thread libvalhalla_loki.la
libtool: link: g++ -Ivalhalla -g -O2 -std=c++11 -o test/.libs/loki_service test/test_loki_service-loki_service.o test/test_loki_service-test.o  -L/usr/lib/x86_64-linux-gnu -L/usr/local/lib -lboost_program_options ./.libs/libvalhalla_loki.so -lprime_server /usr/local/lib/libvalhalla_sif.so /usr/local/lib/libvalhalla_baldr.so /usr/local/lib/libvalhalla_midgard.so -lboost_filesystem -lboost_regex -lboost_date_time -lboost_system -lboost_thread
/usr/bin/ld: test/test_loki_service-loki_service.o: undefined reference to symbol 'pthread_create@@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

I agree, if libtool intends to handle this flag, then we should let it do this. Please consider close this issue.

ill let this open until we can figure out how to make libtool at this reliably. i dont pretend to understand the full mechanics of it so a bit of research will be in order first!

ptpt commented

Yup let me know if you figure it out!

A workaround for the moment is passing -pthread to install.sh

CXXFLAGS=-pthread ./scripts/install.sh