cmake hits undefined reference to `pthread_create' - FindThreads error
i made an attempt to build LibreCAD 3 from master branch https://github.com/LibreCAD/LibreCAD_3
the git clones is well ok, but at the cmake step i got an error
Building C object CMakeFiles/cmTC_1b545.dir/CheckSymbolExists.c.o
...
/usr/bin/cc -rdynamic CMakeFiles/cmTC_1b545.dir/CheckSymbolExists.c.o -o cmTC_1b545
/usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: CMakeFiles/cmTC_1b545.dir/CheckSymbolExists.c.o: in function `main':
CheckSymbolExists.c:(.text+0x16): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
/* */
#include <pthread.h>
int main(int argc, char** argv)
{
(void)argv;
#ifndef pthread_create
return ((int*)(&pthread_create))[argc];
#else
(void)argc;
return 0;
#endif
}
note that the boost c++ or standard lib threads library is also used in that project
the cmake version used is 3.10.2, this version is currently distributed with OpenSuse Leap 15.1 Linux distribution
this happens whenever there is find_package(Threads)
statements in CMakeLists.txt files
while trying to resolve the problem i traced the problem to /usr/share/cmake/Modules/FindThreads.cmake apparently when FindThreads.cmake attempt to verify pthreads by compiling a test c/c++ file it did not pass the parameter -pthread or -lpthread to the compiler cc/c++ or linker. this cause the compile to fail with the above error. i tried to resolve the issue by downloading FindThreads.cmake from the git repository and using that. i'm getting a similar but different error as the new test codes are slightly different. the problem is the same, during the test -pthread or -lpthread is not passed to the linker or compiler so the link always fails