对符号“pthread_key_delete@glibc_2.2.5”的未定义引用

时间:2022-06-19 17:44:57

I'm trying to make a file in Ubuntu and when i make i keep getting this error:

我正在尝试在Ubuntu中创建一个文件,当我创建的时候,我不断地得到这个错误:

/usr/bin/ld: ../../gtest-1.7.0/libgtest.a(gtest-all.cc.o): undefined reference to symbol     'pthread_key_delete@@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
make[2]: *** [src/tests/run_tests] Error 1
make[1]: *** [src/tests/CMakeFiles/run_tests.dir/all] Error 2
make: *** [all] Error 2

I saw someone mentioning to go into Makefile and adding '-L /lib64 -l pthread' to the variable LDFLAGS but how do you do that? Totally new to linux here =X

我看到有人提到要进入Makefile并在变量LDFLAGS中添加“-L /lib64 -L pthread”但是你怎么做呢?这里的linux是全新的=X

2 个解决方案

#1


16  

The above linking problem is solved by adding

上面的链接问题是通过添加来解决的

-lpthread -lm to CMakeLists.txt (target link libraries for luxrender);
TARGET_LINK_LIBRARIES(... -lpthread -lm)

Best regards,

最好的问候,

#2


2  

I hit the same issue: -lpthread should be last in your linking invocation (has to do with mix of static and shared symbols)

我遇到了同样的问题:-lpthread应该是链接调用中的最后一个(必须使用静态和共享符号的混合)

So with CMake: ${CMAKE_THREAD_LIBS_INIT} should be last. For example:

所以使用CMake: ${CMAKE_THREAD_LIBS_INIT}应该是最后一个。例如:

target_link_libraries(mytestlib
  ${BINARY_DIR}/libgmock.a
  glog
  gflags
  ${Boost_LIBRARIES}
  ${CMAKE_THREAD_LIBS_INIT}
)

And for the OP: Search for "thread" in the CMakeLists.txt for the project your are building and paste those section (or link which project you are trying to build if it is open source) - if the above isn't self explanatory

对于OP:在CMakeLists中搜索“线程”。txt用于您正在构建的项目,并粘贴那些部分(或者如果是开源项目,您将尝试构建哪个项目)——如果上面的内容不是不言自明的话

#1


16  

The above linking problem is solved by adding

上面的链接问题是通过添加来解决的

-lpthread -lm to CMakeLists.txt (target link libraries for luxrender);
TARGET_LINK_LIBRARIES(... -lpthread -lm)

Best regards,

最好的问候,

#2


2  

I hit the same issue: -lpthread should be last in your linking invocation (has to do with mix of static and shared symbols)

我遇到了同样的问题:-lpthread应该是链接调用中的最后一个(必须使用静态和共享符号的混合)

So with CMake: ${CMAKE_THREAD_LIBS_INIT} should be last. For example:

所以使用CMake: ${CMAKE_THREAD_LIBS_INIT}应该是最后一个。例如:

target_link_libraries(mytestlib
  ${BINARY_DIR}/libgmock.a
  glog
  gflags
  ${Boost_LIBRARIES}
  ${CMAKE_THREAD_LIBS_INIT}
)

And for the OP: Search for "thread" in the CMakeLists.txt for the project your are building and paste those section (or link which project you are trying to build if it is open source) - if the above isn't self explanatory

对于OP:在CMakeLists中搜索“线程”。txt用于您正在构建的项目,并粘贴那些部分(或者如果是开源项目,您将尝试构建哪个项目)——如果上面的内容不是不言自明的话