I'm using 64-bit gcc-4.8.2 to generate a 32-bit target, and my machine is 64-bit. I'm using c++11 concurrency features such as thread, mutex, conditiona_variables and etc.
The linker gave the above error message when trying to link the executable. libMyLib is also part of the project.
libMyLib.so: undefined reference to '__gthrw___pthread_key_create(unsigned int*, void (*)(void*))
nm libMyLib.so | grep pthread_key_create shows:
U _ZL28__gthrw___pthread_key_createPjPFvPvE
w __pthread_key_create@@GLIBC_2.0
where is the symbol 'ghtrw___pthread_key_create' from? I tried adding '-lpthread(-pthread)' as compiler flag, but it does not help.
More information. nm libMyLib.so | grep pthread shows other symbols such as _ZL20__gthread_mutex_lockP15pthread_mutex_t is defined
It is defined in GCC's "gthreads" abstraction layer for thread primitives, in the
gthr-posix.h
header.After preprocessing that expands to:
It is supposed to be a weak reference to
__pthread_key_create
, so it should never have a definition, because it is just a reference to glibc's internal__pthread_key_create
symbol.So it looks like something has gone wrong with how you build you library. You should not have an undefined weak symbol.