undefined reference to symbol ‘pthread_create‘解决方法

运行make -j4 时出现如下错误

/usr/bin/ld: CMakeFiles/DC.dir/src/main.cpp.o: undefined reference to symbol 'pthread_create@@GLIBC_2.2.5'
/usr/bin/ld: /lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/DC.dir/build.make:156: DC] Error 1
make[1]: *** [CMakeFiles/Makefile2:513: CMakeFiles/DC.dir/all] Error 2

从上面报错信息看到是在CMakeFiles/DC.dir/build.make的156行
打开build.make. 找到156行

        $(CMAKE_COMMAND) -E cmake_link_script CMakeFiles/DC.dir/link.txt --verbose=$(VERBOSE)

看到一个链接文件link.txt
打开CMakeFiles/DC.dir/link.txt, 看到很多lib,
在这些lib的间隔中,插入-lpthread即解决。

或者在CMakeLists.txt的target_link中加入-lpthread

target_link_libraries( MyProject LIB1 LIB2 -lpthread)

你可能感兴趣的:(环境,人工智能)