Undefined reference to symbol ‘pthread_create@@GLIBC_2.2.5’

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

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)