2015-01-19 15 views
5

Oto moje środowisko:Jak niech użycie cmake "-pthread" zamiast -lpthread "

  • OS: Ubuntu 14.10
  • gcc 4.9
  • CUpewnij: 2.8, 3.1 (zarówno próbował)
  • projekt: muduo

Niedawno zacząłem uczyć się programowania sieciowego i pobierz muduo do nauki Chociaż mam problemy zbudować źródło, BEC. ause cmake będzie narzekał z "nie można znaleźć -lpthreads".

Zrobiłem kilka badań. Jest to głównie spowodowane przez nowszą wersję gcc w systemie Ubuntu 14.10. Gcc-4.9 użyje "-pthread" do połączenia z biblioteką pthread, jednak starsza wersja gcc używa "-lpthreads". Wydaje się, że CUpewnij nadal używa „-lpthreads”, a ja nie wiem jak rozwiązać ten problem ...

Poniżej znajduje się dziennik błędów:

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 

ktoś wie jak to naprawić i pozwól mi skompilować muduo na Ubuntu 14.10?

+2

Czy używasz 'find_package (Threads REQUIRED)' w twoim 'CMakeLists.txt' lub co? Powinieneś pokazać swój plik .. – stefan

+0

Sprawdź tutaj, czy to pomaga http://stackoverflow.com/questions/23250863/difference-between-pthread-and-lpthread-while-compiling – DumbCoder

+0

Właśnie otrzymałem odpowiedź od autora muduo. To z powodu braku libboost-dev. Komunikat o błędzie jest mylący ... –

Odpowiedz

4

Zestaw z kompilacji lub łącze flagi cel:

set_target_properties(target1 PROPERTIES COMPILE_FLAGS -pthread LINK_FLAGS -pthread) 

lub ustawić zmienne globalne:

set(CMAKE_LINKER_FLAGS "-pthread" CACHE STRING "Linker Flags" FORCE) 
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_LINKER_FLAGS}" CACHE STRING "" FORCE) 
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS}" CACHE STRING "" FORCE) 
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS}" CACHE STRING "" FORCE) 
0

Właśnie otrzymałem odpowiedź od autora muduo. Jest to spowodowane brakiem libboost-dev. Komunikat o błędzie jest mylący.

Po zastosować następującą komendę:

sudo apt-get install g++ libboost-dev cmake make git 

Build uda.

+1

Mam zainstalowane wszystkie te pakiety, problem nie jest związany z zainstalowanymi pakietami. – Avio

Powiązane problemy