Wie wir cmake verwenden "-pthread" statt -lpthread"?

Hier ist meine Umgebung:

  • OS: Ubuntu 14.10
  • gcc: 4.9
  • cmake: 2.8, 3.1(beide probiert)
  • Projekt: muduo

Vor kurzem habe ich angefangen, zu lernen, Netzwerk-Programmierung und download muduo für das lernen. Während ich Probleme haben, zu bauen, die Quelle, weil cmake wird sich beschweren, mit "cannot find -lpthreads".

Ich habe einige der Forschung getan. Es ist meist verursacht durch die neuere version von gcc in Ubuntu 14.10. Die gcc-4.9 wird mit "-pthread" link zu der pthread-Bibliothek, jedoch die ältere version von gcc verwendet "-lpthreads". Es scheint, dass cmake verwendet immer noch "-lpthreads" und ich weiß nicht, wie diese zu beheben...

Unten ist der error log:

  File /home/jack/workspace/github/build/release/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/jack/workspace/github/build/release/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTryCompileExec2265723491/fast"
/usr/bin/make -f CMakeFiles/cmTryCompileExec2265723491.dir/build.make CMakeFiles/cmTryCompileExec2265723491.dir/build
make[1]: Entering directory '/home/jack/workspace/github/build/release/CMakeFiles/CMakeTmp'
/usr/local/bin/cmake -E cmake_progress_report /home/jack/workspace/github/build/release/CMakeFiles/CMakeTmp/CMakeFiles 1
Building C object CMakeFiles/cmTryCompileExec2265723491.dir/CheckFunctionExists.c.o
/usr/bin/cc   -DCHECK_FUNCTION_EXISTS=pthread_create   -o CMakeFiles/cmTryCompileExec2265723491.dir/CheckFunctionExists.c.o   -c /usr/local/share/cmake-3.1/Modules/CheckFunctionExists.c
Linking C executable cmTryCompileExec2265723491
/usr/local/bin/cmake -E cmake_link_script CMakeFiles/cmTryCompileExec2265723491.dir/link.txt --verbose=1
/usr/bin/cc   -DCHECK_FUNCTION_EXISTS=pthread_create   CMakeFiles/cmTryCompileExec2265723491.dir/CheckFunctionExists.c.o  -o cmTryCompileExec2265723491 -rdynamic -lpthreads 
/usr/bin/ld: cannot find -lpthreads
collect2: error: ld returned 1 exit status
CMakeFiles/cmTryCompileExec2265723491.dir/build.make:88: recipe for target 'cmTryCompileExec2265723491' failed
make[1]: Leaving directory '/home/jack/workspace/github/build/release/CMakeFiles/CMakeTmp'
Makefile:118: recipe for target 'cmTryCompileExec2265723491/fast' failed
make[1]: *** [cmTryCompileExec2265723491] Error 1
make: *** [cmTryCompileExec2265723491/fast] Error 2

Jemand weiß, wie man dieses Problem beheben und lassen Sie mich kompilieren muduo auf Ubuntu 14.10?

  • Verwenden Sie find_package(Threads REQUIRED) in Ihrem CMakeLists.txt oder was? Sie sollten zeigen Sie Ihre Datei..
  • Prüfen Sie hier, wenn es hilft, stackoverflow.com/questions/23250863/...
  • Ich habe soeben Antwort vom Autor muduo. Ist es, weil der Mangel an libboost-dev. Die Fehlermeldung ist irreführend,...
InformationsquelleAutor Jack Sun | 2015-01-19
Schreibe einen Kommentar