Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined reference to symbol 'pthread_key_delete@@GLIBC_2.2.5

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

like image 996
imolital Avatar asked Sep 02 '14 07:09

imolital


People also ask

How to edit makefile to add pthreads?

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.

What Directory should I add libpthread to?

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.

Should-lpthread be last in your linking invocation?

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:


3 Answers

The above linking problem is solved by adding

-lpthread -lm to CMakeLists.txt (target link libraries for luxrender);
TARGET_LINK_LIBRARIES(... -lpthread -lm)
like image 195
user4587644 Avatar answered Oct 03 '22 05:10

user4587644


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

like image 38
Laurent Demailly Avatar answered Oct 03 '22 03:10

Laurent Demailly


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})
like image 41
bobah Avatar answered Oct 03 '22 04:10

bobah