web-dev-qa-db-fra.com

CMake ne détectant pas les pthreads en raison d'avertissements

Je reçois une erreur lors de la création d'un projet avec CMake:

-- Could NOT find Threads (missing:  Threads_FOUND)

Le journal des erreurs montre que CMake a trébuché sur quelque chose de vraiment banal:

/usr/bin/cc   -std=c11 -D_GNU_SOURCE   -Wall -Wextra -Wpointer-arith -Wundef -Wvla -Wwrite-strings -Werror -Wno-error=extra -Wno-error=deprecated-declarations -Wno-error=sign-compare -Wno-error=strict-aliasing -Wno-error=type-limits -Wno-unused-parameter -Wno-error=unused-variable -Wno-error=undef -Wno-error=uninitialized -Wlogical-op -Wno-error=maybe-uninitialized -Waggregate-return -Wnested-externs -Wold-style-definition -Wstrict-prototypes -march=native    -o CMakeFiles/cmTryCompileExec2533162744.dir/CheckIncludeFiles.c.o   -c /mnt/shared/fooproj/build/release/CMakeFiles/CMakeTmp/CheckIncludeFiles.c
/mnt/shared/fooproj/build/release/CMakeFiles/CMakeTmp/CheckIncludeFiles.c:5:5: 
     error: function declaration isn’t a prototype [-Werror=strict-prototypes]
 int main(){return 0;}
 ^
/mnt/shared/fooproj/build/release/CMakeFiles/CMakeTmp/CheckIncludeFiles.c: 
     In function ‘main’:
/mnt/shared/fooproj/build/release/CMakeFiles/CMakeTmp/CheckIncludeFiles.c:5:5: 
     error: old-style function definition [-Werror=old-style-definition]
cc1: all warnings being treated as errors
[...]
Source:
/* */
#include <pthread.h>


int main(){return 0;}

Cela ne devrait vraiment pas être une raison pour que CMake pense que les threads n'existent pas. Comment puis-je résoudre ce problème?

11
Claudiu

Je crois que c'est bogue CMake 15058 que je viens de signaler.

Le test que CMake utilise pour vérifier le fichier include utilise une définition de fonction C à l'ancienne. Si -Wold-style-definition -Werror Est en vigueur, gcc va barf sur ce point.

J'ai inclus un correctif dans le rapport de bogue lié ci-dessus, mais pour une solution rapide, recherchez le fichier Modules/CheckIncludeFiles.cmake Dans votre installation CMake (éventuellement dans /usr/share/cmake Ou similaire), trouvez la ligne

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

et changez int main() en int main(void).

24
Nate Eldredge

Le problème semble être toujours là. J'essaie de compiler les nominatim lates. semble avoir la même erreur.

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

Éditer: cmake -lpthread .. semble résoudre ce problème

1
Annihilator708