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?
Czy używasz 'find_package (Threads REQUIRED)' w twoim 'CMakeLists.txt' lub co? Powinieneś pokazać swój plik .. – stefan
Sprawdź tutaj, czy to pomaga http://stackoverflow.com/questions/23250863/difference-between-pthread-and-lpthread-while-compiling – DumbCoder
Właśnie otrzymałem odpowiedź od autora muduo. To z powodu braku libboost-dev. Komunikat o błędzie jest mylący ... –