CMake failing to detect pthreads due to warnings

后端 未结 2 734
猫巷女王i
猫巷女王i 2020-12-16 16:49

I get an error when making a project with CMake:

-- Could NOT find Threads (missing:  Threads_FOUND)

The error log shows that CMake tripped

相关标签:
2条回答
  • 2020-12-16 17:25

    Issue seems to be still there. I try to compile the lates nominatim. seems i got the same error.

    Determining if the pthread_create exist failed with the following output:
    Change Dir: /home/mikelaptop/Desktop/nominatim/290102/Nominatim/build/CMakeFiles/CMakeTmp
    
    Run Build Command:"/usr/bin/make" "cmTC_b87d8/fast"
    /usr/bin/make -f CMakeFiles/cmTC_b87d8.dir/build.make CMakeFiles/cmTC_b87d8.dir/build
    make[1]: Entering directory '/home/mikelaptop/Desktop/nominatim/290102/Nominatim/build/CMakeFiles/CMakeTmp'
    Building C object CMakeFiles/cmTC_b87d8.dir/CheckSymbolExists.c.o
    /usr/bin/cc    -o CMakeFiles/cmTC_b87d8.dir/CheckSymbolExists.c.o   -c /home/mikelaptop/Desktop/nominatim/290102/Nominatim/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c
    Linking C executable cmTC_b87d8
    /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_b87d8.dir/link.txt --verbose=1
    /usr/bin/cc      -rdynamic CMakeFiles/cmTC_b87d8.dir/CheckSymbolExists.c.o  -o cmTC_b87d8 
    CMakeFiles/cmTC_b87d8.dir/CheckSymbolExists.c.o: In function `main':
    CheckSymbolExists.c:(.text+0x1b): undefined reference to `pthread_create'
    collect2: error: ld returned 1 exit status
    CMakeFiles/cmTC_b87d8.dir/build.make:97: recipe for target 'cmTC_b87d8' failed
    make[1]: *** [cmTC_b87d8] Error 1
    make[1]: Leaving directory '/home/mikelaptop/Desktop/nominatim/290102/Nominatim/build/CMakeFiles/CMakeTmp'
    Makefile:126: recipe for target 'cmTC_b87d8/fast' failed
    make: *** [cmTC_b87d8/fast] Error 2
    
    File /home/mikelaptop/Desktop/nominatim/290102/Nominatim/build/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: /home/mikelaptop/Desktop/nominatim/290102/Nominatim/build/CMakeFiles/CMakeTmp
    
    Run Build Command:"/usr/bin/make" "cmTC_eb9e3/fast"
    /usr/bin/make -f CMakeFiles/cmTC_eb9e3.dir/build.make CMakeFiles/cmTC_eb9e3.dir/build
    make[1]: Entering directory '/home/mikelaptop/Desktop/nominatim/290102/Nominatim/build/CMakeFiles/CMakeTmp'
    Building C object CMakeFiles/cmTC_eb9e3.dir/CheckFunctionExists.c.o
    /usr/bin/cc   -DCHECK_FUNCTION_EXISTS=pthread_create   -o CMakeFiles/cmTC_eb9e3.dir/CheckFunctionExists.c.o   -c /usr/share/cmake-3.9/Modules/CheckFunctionExists.c
    Linking C executable cmTC_eb9e3
    /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_eb9e3.dir/link.txt --verbose=1
    /usr/bin/cc  -DCHECK_FUNCTION_EXISTS=pthread_create    -rdynamic CMakeFiles/cmTC_eb9e3.dir/CheckFunctionExists.c.o  -o cmTC_eb9e3 -lpthreads 
    /usr/bin/ld: cannot find -lpthreads
    collect2: error: ld returned 1 exit status
    CMakeFiles/cmTC_eb9e3.dir/build.make:97: recipe for target 'cmTC_eb9e3' failed
    make[1]: *** [cmTC_eb9e3] Error 1
    make[1]: Leaving directory '/home/mikelaptop/Desktop/nominatim/290102/Nominatim/build/CMakeFiles/CMakeTmp'
    Makefile:126: recipe for target 'cmTC_eb9e3/fast' failed
    make: *** [cmTC_eb9e3/fast] Error 2
    

    Edit: cmake -lpthread .. seems to fix this

    0 讨论(0)
  • 2020-12-16 17:26

    I believe this is CMake bug 15058 which I just reported.

    The test that CMake is using to check the include file uses an old-style C function definition. If -Wold-style-definition -Werror is in effect, gcc will barf on this.

    I included a patch in the bug report linked above, but for a quick fix, find the file Modules/CheckIncludeFiles.cmake in your CMake installation (possibly in /usr/share/cmake or similar), find the line

      "${CMAKE_CONFIGURABLE_FILE_CONTENT}\n\nint main(){return 0;}\n")
    

    and change int main() to int main(void).

    0 讨论(0)
提交回复
热议问题