I'm trying to make a file in Ubuntu and when i make i keep getting this error:
/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
There is no need to edit the Makefile as suggested in the previous answer. Rather, the workaround is to specify LDFLAGS='-pthread' when configuring the build; for example: I've filed bug report #1364 with the Bochs project.
Of cause, you should also add the directory of libpthread to your library directories. Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question.
Show activity on this post. 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:
The above linking problem is solved by adding
-lpthread -lm to CMakeLists.txt (target link libraries for luxrender);
TARGET_LINK_LIBRARIES(... -lpthread -lm)
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})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With