यहाँ मेरी वातावरण है:जाने के लिए कैसे cmake उपयोग "-pthread" के बदले -lpthread "
- ओएस: उबंटू 14.10
- जीसीसी: 4.9
- cmake: 2.8, 3.1 (दोनों की कोशिश की)
- परियोजना: muduo
हाल ही में, मैं नेटवर्क प्रोग्रामिंग जानने के लिए और सीखने के लिए डाउनलोड करने के लिए muduo, शुरू कर दिया है जबकि मैं स्रोत का निर्माण करने की समस्या है बीईसी। Ause cmake "शिकायत नहीं कर सकता" के साथ शिकायत करेगा।
मैंने कुछ शोध किया है। यह ज्यादातर उबंटू 14.10 के तहत जीसीसी के नए संस्करण के कारण होता है। Gcc-4.9 pthread लाइब्रेरी से लिंक करने के लिए "-pthread" का उपयोग करेगा, हालांकि, जीसीसी का पुराना संस्करण "-lpthreads" का उपयोग करता है। ऐसा लगता है कि cmake अभी भी "-lpthreads" का उपयोग करता है और मैं यह कैसे सही करने के लिए नहीं पता ...
नीचे त्रुटि लॉग है:
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
किसी को जानता है इसे ठीक है और मुझे संकलन जाने के लिए उबुंटू 14.10 पर muduo?
क्या आप अपने 'CMakeLists.txt' में 'find_package (थ्रेड आवश्यक)' का उपयोग करते हैं या क्या? आपको अपनी फाइल दिखानी चाहिए .. – stefan
यहां जांचें, अगर यह http://stackoverflow.com/questions/23250863/difference-between-pthread-and-lpthread-while-compiling – DumbCoder
में मदद करता है तो मुझे अभी लेखक का जवाब मिला है muduo। यह libboost-dev की कमी के कारण है। त्रुटि संदेश भ्रामक है ... –