c++11 - 对 '__gthrw___pthread_key_create(unsigned int*, void (*)(void*)) 的 undefined reference

标签 c++11 gcc opensuse gcc4.8

我正在使用 64 位 gcc-4.8.2 生成 32 位目标,而我的机器是 64 位。我正在使用 c++11 并发功能,例如线程、互斥锁、conditiona_variables 等。

链接器在尝试链接可执行文件时给出了上述错误消息。 libMyLib 也是该项目的一部分。

libMyLib.so: undefined reference to '__gthrw___pthread_key_create(unsigned int*, void (*)(void*))

nm libMyLib.so | grep pthread_key_create 显示:
U _ZL28__gthrw___pthread_key_createPjPFvPvE
w __pthread_key_create@@GLIBC_2.0

符号“ghtrw___pthread_key_create”来自哪里?我尝试添加 '-lpthread(-pthread)' 作为编译器标志,但它没有帮助。

更多信息。 nm libMyLib.so | grep pthread 显示定义了其他符号,例如 _ZL20__gthread_mutex_lockP15pthread_mutex_t

最佳答案

where is the symbol 'ghtrw___pthread_key_create' from?



它在 GCC 的线程原语的“gthreads”抽象层中定义,在 gthr-posix.h 中。标题。
#if SUPPORTS_WEAK && GTHREAD_USE_WEAK
# ifndef __gthrw_pragma
#  define __gthrw_pragma(pragma)
# endif
# define __gthrw2(name,name2,type) \
  static __typeof(type) name __attribute__ ((__weakref__(#name2))); \
  __gthrw_pragma(weak type)
# define __gthrw_(name) __gthrw_ ## name
#else
# define __gthrw2(name,name2,type)
# define __gthrw_(name) name
#endif

/* Typically, __gthrw_foo is a weak reference to symbol foo.  */
#define __gthrw(name) __gthrw2(__gthrw_ ## name,name,name)

...

#ifdef __GLIBC__
__gthrw2(__gthrw_(__pthread_key_create),
     __pthread_key_create,
     pthread_key_create)

预处理后扩展为:
static __typeof(pthread_key_create) __gthrw___pthread_key_create __attribute__ ((__weakref__("__pthread_key_create")));

它应该是对 __pthread_key_create 的弱引用,所以它永远不应该有定义,因为它只是对 glibc 内部 __pthread_key_create 的引用象征。

因此,您构建库的方式似乎出了点问题。你不应该有一个未定义的弱符号。

关于c++11 - 对 '__gthrw___pthread_key_create(unsigned int*, void (*)(void*)) 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27257655/

相关文章:

c++ - 针对 libx264 的链接不起作用 (Cygwin)

android - 无法在 Linux 中启动 Android Studio

php 错误显示未定义的 mysqli_query

c++ - 函数模板的 typedef(部分实例化)

c++ - 所有的模板实例都是在编译时创建的吗?

c++ - 先前初始化内存是否保证在放置新调用后持续存在?

c++ - make 说 : `No rule to make target` when I try to compile a Qt application for android platfrom

linux - 如何使用 makefile 执行 C++11

c++ - 为什么 gcc 和 NVCC (g++) 看到两种不同的结构大小?

ubuntu - vgaswitcheroo 状态变化