xswang/xflow

undefined reference to symbol 'pthread_create@@GLIBC_2.2.5'

chenlongzhen opened this issue · 3 comments

cmake .
make
编译报错,请问这是什么问题? 在cmakefile.txt加了 add_definitions('-pthread') 也是样的错误
[100%] Linking CXX executable ../../test/src/xflow_lr
/usr/bin/ld: CMakeFiles/xflow_lr.dir/main.cc.o: undefined reference to symbol 'pthread_create@@GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
src/model/CMakeFiles/xflow_lr.dir/build.make:174: recipe for target 'test/src/xflow_lr' failed
make[2]: *** [test/src/xflow_lr] Error 1
CMakeFiles/Makefile2:196: recipe for target 'src/model/CMakeFiles/xflow_lr.dir/all' failed
make[1]: *** [src/model/CMakeFiles/xflow_lr.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

what is your OS? centOS or Ubuntu?

我也遇到了这个问题,这是由于pthread库不是linux默认的库,需要在链接时使用静态库libpthread.a
具体操作方案在src/mode/cmakelists.txt中加入以下指令:
find_package(Threads REQUIRED)
if(THREADS_HAVE_PTHREAD_ARG)
set_property(TARGET xflow_lr PROPERTY COMPILE_OPTIONS "-pthread")
set_property(TARGET xflow_lr PROPERTY INTERFACE_COMPILE_OPTIONS "-pthread")
endif()
if(CMAKE_THREAD_LIBS_INIT)
target_link_libraries(xflow_lr "${CMAKE_THREAD_LIBS_INIT}")
endif()