[CMake] find_package not finding Threads

Andrew Brownsword andrew.e.brownsword at gmail.com
Sat Apr 7 12:46:56 EDT 2018


I updated to CMake 3.11.0, but still got the same error.  I have gotten around the problem by removing the find_package and forcing -pthread on the C/C++ command line, however this is an unsatisfying resolution to the problem.

> On Mar 30, 2018, at 12:06 PM, Andrew Brownsword <andrew.e.brownsword at gmail.com> wrote:
> 
> I have an Ubuntu 16.04 ARMv7 system upon which I have built CLang 7.0 and am now trying to use it to build my CMake-based project that was previously working with the CLang 3.8.0 that I had installed via apt-get.  The new compiler does appear to be selected correctly when I run cmake.  The run fails when it tries this find_package call:
> 
> set(THREADS_PREFER_PTHREAD_FLAG ON)
> find_package(Threads REQUIRED)
> 
> 
> With this error:
> 
> CMake Error at /usr/local/share/cmake-3.8/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
>   Could NOT find Threads (missing: Threads_FOUND)
> Call Stack (most recent call first):
>   /usr/local/share/cmake-3.8/Modules/FindPackageHandleStandardArgs.cmake:377 (_FPHSA_FAILURE_MESSAGE)
>   /usr/local/share/cmake-3.8/Modules/FindThreads.cmake:212 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
>   src/libraries/civetweb/CMakeLists.txt:8 (find_package)
> 
> 
> 
> The libpthread.so resides in /usr/lib/arm-linux-gnueabihf/ on this system.  I am *not* cross-compiling, and I built CLang on the system itself.  I’ve looked at the REGEX that CMake is supposed to use to find this subdirectory and it looks correct (and it did work with CLang 3.8.0).
> 
> Any suggestions?
> 
> 
> 
> 
> 
> 
> The CMakeError.log file contains this:
> 
> Determining if the pthread_create exist failed with the following output:
> Change Dir: ~/CMakeFiles/CMakeTmp
> 
> Run Build Command:"/usr/bin/make" "cmTC_1d4b8/fast"
> /usr/bin/make -f CMakeFiles/cmTC_1d4b8.dir/build.make CMakeFiles/cmTC_1d4b8.dir/build
> make[1]: Entering directory '~/CMakeFiles/CMakeTmp'
> Building C object CMakeFiles/cmTC_1d4b8.dir/CheckSymbolExists.c.o
> /usr/bin/clang   -Wall -fno-strict-aliasing    -o CMakeFiles/cmTC_1d4b8.dir/CheckSymbolExists.c.o   -c ~/CMakeFiles/CMakeTmp/CheckSymbolExists.c
> Linking C executable cmTC_1d4b8
> /usr/local/bin/cmake -E cmake_link_script CMakeFiles/cmTC_1d4b8.dir/link.txt --verbose=1
> /usr/bin/clang  -Wall -fno-strict-aliasing     CMakeFiles/cmTC_1d4b8.dir/CheckSymbolExists.c.o  -o cmTC_1d4b8 
> CMakeFiles/cmTC_1d4b8.dir/CheckSymbolExists.c.o: In function `main':
> ~/CMakeFiles/CMakeTmp/CheckSymbolExists.c:(.text+0x4): undefined reference to `pthread_create'
> ~/CMakeFiles/CMakeTmp/CheckSymbolExists.c:(.text+0x8): undefined reference to `pthread_create'
> ~/CMakeFiles/CMakeTmp/CheckSymbolExists.c:(.text+0x24): undefined reference to `pthread_create'
> ~/CMakeFiles/CMakeTmp/CheckSymbolExists.c:(.text+0x28): undefined reference to `pthread_create'
> clang: error: linker command failed with exit code 1 (use -v to see invocation)
> CMakeFiles/cmTC_1d4b8.dir/build.make:97: recipe for target 'cmTC_1d4b8' failed
> make[1]: *** [cmTC_1d4b8] Error 1
> make[1]: Leaving directory '~/CMakeFiles/CMakeTmp'
> Makefile:126: recipe for target 'cmTC_1d4b8/fast' failed
> make: *** [cmTC_1d4b8/fast] Error 2
> 
> File ~/CMakeFiles/CMakeTmp/CheckSymbolExists.c:
> /* */
> #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
> }
> 
> Determining if the function pthread_create exists in the pthreads failed with the following output:
> Change Dir: ~/CMakeFiles/CMakeTmp
> 
> Run Build Command:"/usr/bin/make" "cmTC_81507/fast"
> /usr/bin/make -f CMakeFiles/cmTC_81507.dir/build.make CMakeFiles/cmTC_81507.dir/build
> make[1]: Entering directory '~/CMakeFiles/CMakeTmp'
> Building C object CMakeFiles/cmTC_81507.dir/CheckFunctionExists.c.o
> /usr/bin/clang   -Wall -fno-strict-aliasing -DCHECK_FUNCTION_EXISTS=pthread_create   -o CMakeFiles/cmTC_81507.dir/CheckFunctionExists.c.o   -c /usr/local/share/cmake-3.8/Modules/CheckFunctionExists.c
> Linking C executable cmTC_81507
> /usr/local/bin/cmake -E cmake_link_script CMakeFiles/cmTC_81507.dir/link.txt --verbose=1
> /usr/bin/clang  -Wall -fno-strict-aliasing -DCHECK_FUNCTION_EXISTS=pthread_create    CMakeFiles/cmTC_81507.dir/CheckFunctionExists.c.o  -o cmTC_81507 -lpthreads 
> /usr/bin/ld: cannot find -lpthreads
> clang: error: linker command failed with exit code 1 (use -v to see invocation)
> CMakeFiles/cmTC_81507.dir/build.make:97: recipe for target 'cmTC_81507' failed
> make[1]: *** [cmTC_81507] Error 1
> make[1]: Leaving directory '~/CMakeFiles/CMakeTmp'
> Makefile:126: recipe for target 'cmTC_81507/fast' failed
> make: *** [cmTC_81507/fast] Error 2
> 
> 
> Determining if the include file pthread.h exists failed with the following output:
> Change Dir: ~/CMakeFiles/CMakeTmp
> 
> Run Build Command:"/usr/bin/make" "cmTC_83cc7/fast"
> /usr/bin/make -f CMakeFiles/cmTC_83cc7.dir/build.make CMakeFiles/cmTC_83cc7.dir/build
> make[1]: Entering directory '~/CMakeFiles/CMakeTmp'
> Building C object CMakeFiles/cmTC_83cc7.dir/CheckIncludeFile.c.o
> /usr/local/bin/clang   -Wall -fno-strict-aliasing    -o CMakeFiles/cmTC_83cc7.dir/CheckIncludeFile.c.o   -c ~/CMakeFiles/CMakeTmp/CheckIncludeFile.c
> In file included from ~/CMakeFiles/CMakeTmp/CheckIncludeFile.c:1:
> In file included from /usr/include/pthread.h:23:
> /usr/include/sched.h:28:10: fatal error: 'stddef.h' file not found
> #include <stddef.h>
>          ^~~~~~~~~~
> 1 error generated.
> CMakeFiles/cmTC_83cc7.dir/build.make:65: recipe for target 'CMakeFiles/cmTC_83cc7.dir/CheckIncludeFile.c.o' failed
> make[1]: *** [CMakeFiles/cmTC_83cc7.dir/CheckIncludeFile.c.o] Error 1
> make[1]: Leaving directory '~/CMakeFiles/CMakeTmp'
> Makefile:126: recipe for target 'cmTC_83cc7/fast' failed
> make: *** [cmTC_83cc7/fast] Error 2
> 
> 
> 
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180407/9d608736/attachment.html>


More information about the CMake mailing list