Missing -lpthread when linking with cmake_build.py
seanbaxter opened this issue · 1 comments
Most everything seems to compile and link, except tests relying on pthreads. bsls_splinlock.t is the first test to break the build.
The link.txt shows this:
/usr/bin/circle -O2 -DNDEBUG CMakeFiles/bsls_spinlock.t.dir/groups/bsl/bsls/bsls_spinlock.t.cpp.o -o bsls_spinlock.t libbsls.
The terminal output complains about no pthread:
Scanning dependencies of target bsls_spinlock.t
[ 23%] Building CXX object CMakeFiles/bsls_spinlock.t.dir/groups/bsl/bsls/bsls_spinlock.t.cpp.o
[ 23%] Linking CXX executable bsls_spinlock.t
CMakeFiles/bsls_spinlock.t.dir/groups/bsl/bsls/bsls_spinlock.t.cpp.o: In function createThread(void* (*)(void*), void*)': bsls_spinlock.t.cpp:(.text+0x7f): undefined reference to
pthread_create'
CMakeFiles/bsls_spinlock.t.dir/groups/bsl/bsls/bsls_spinlock.t.cpp.o: In function joinThread(unsigned long)': bsls_spinlock.t.cpp:(.text+0xb3): undefined reference to
pthread_join'
error: linker failed with exit code 1
CMakeFiles/bsls_spinlock.t.dir/build.make:104: recipe for target 'bsls_spinlock.t' failed
make[3]: *** [bsls_spinlock.t] Error 1
CMakeFiles/Makefile2:6345: recipe for target 'CMakeFiles/bsls_spinlock.t.dir/all' failed
make[2]: *** [CMakeFiles/bsls_spinlock.t.dir/all] Error 2
CMakeFiles/Makefile2:5637: recipe for target 'CMakeFiles/all.t.dir/rule' failed
make[1]: *** [CMakeFiles/all.t.dir/rule] Error 2
I pasted the bsls_spinlock.t.dir/build.make here:
https://gist.github.com/seanbaxter/3b73ebee7cb034c97d905675767d7a6d
The only thing I can find relevant to pthread is in {build-dir}/bsl.py where
Cflags: -I${includedir} -D_POSIX_PTHREAD_SEMANTICS -D_REENTRANT
Libs: -L${libdir} -lbsl -lpthread -lrt
but these options do not get incorporated by configure into the build files created for my compiler.
What do I need to do to get -lpthread to be included?
You need to add an entry for your compiler (similar to these):
https://github.com/bloomberg/bde-tools/blob/master/cmake/bde_ufid.cmake#L629-L631
Then rerun configure with --clean ( to force compiler detection step).
Another location where you might want to extend the compiler entries are here:
https://github.com/bloomberg/bde-tools/blob/master/cmake/bde_ufid.cmake#L573-L587