Reputation: 471
I just pulled a git repository in which me and my friends are developing an application. When I am running make I am facing this error:
undefined reference to symbol 'pthread_create@@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 Makefile:182: recipe for target 'bin/release/ns' failed make[1]: * [bin/release/ns] Error 1 Makefile:133: recipe for target 'release' failed make: * [release] Error 2
my friend pulled the same branch and he runs it without any problem.
Could you please give me some hints about the fix? Detailed answer would be highly appreciated.
Upvotes: 36
Views: 82278
Reputation: 1061
I've been working on a multi-platform game engine and I faced same issue only on Linux. If you are using cmake add following to your cmake file:
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
If you are not using cmake you need to add this flag for your compiler manually.
The complete cmake for using threads in linux systems must contain following commands:
set(CMAKE_THREAD_LIBS_INIT "-lpthread")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
set(CMAKE_HAVE_THREADS_LIBRARY 1)
set(CMAKE_USE_WIN32_THREADS_INIT 0)
set(CMAKE_USE_PTHREADS_INIT 1)
set(THREADS_PREFER_PTHREAD_FLAG ON)
Note: Also this fix works for Mac-Os but with one difference. You don't need to pass -pthread as compiler flag
Upvotes: 65
Reputation: 83
You should add "-lpthread" to your library. Of cause, you should also add the directory of libpthread to your library directories.
Upvotes: 4