undefined reference to symbol 'pthread_key_delete@@GLIBC_2.2.5

时光怂恿深爱的人放手 提交于 2019-12-04 01:31:14
user4587644

The above linking problem is solved by adding

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

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

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

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

If you are building with Make or something else, add -pthread to the compilation command line (so GCC would generate thread-safe static locals) and to the linking command line (so GCC would tell the linker to do the right thing, most notably link with -lpthread).

If you are building with CMake - then most probably you need these (full example):

# always
FIND_PACKAGE(Threads REQUIRED)

# if using boost
SET(Boost_USE_MULTITHREADED ON)

TARGET_LINK_LIBRARIES(my_app ... ${CMAKE_THREAD_LIBS_INIT})
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!