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
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: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):
The above linking problem is solved by adding