2014-12-02 118 views
1

我使用的64位的gcc-4.8.2,以产生一个32位的目标,以及我的机器是64位的。我使用C++ 11并发功能,如线程,互斥,conditiona_variables等未定义参照“__gthrw ___ pthread_key_create(无符号整数*,无效(*)(无效*))

链接器试图将可执行链接时给出了上面的错误消息。 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 [email protected]@GLIBC_2.0 

其中是符号 'ghtrw___pthread_key_create'?我尝试添加'-lpthread(-pthread)'作为编译器标志,但它没有帮助。

更多信息。 nm libMyLib.so | grep的并行线程示出了其它符号如_ZL20__gthread_mutex_lockP15pthread_mutex_t被定义

+0

'我尝试添加“-lpthread”作为编译器flag' - 你知道关于[正确顺序选项(http://stackoverflow.com/questions/18388710/what-is-the-proper-sequence-of-选择换GCC最重要 - 的 - 即序列)? – Gluttton 2014-12-02 19:53:34

+3

改为使用'-pthread'编译器标志。 – 2014-12-02 19:56:35

+0

添加'-pthread'不能解决我的问题。还有一个问题,缺少符号从哪里来? – user11869 2014-12-03 18:28:41

回答

2

哪里是符号“ghtrw___pthread_key_create”从?

它在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符号的引用。

所以它看起来像你建立你的图书馆出了问题。你不应该有一个未定义的弱符号。

+1

上次我看到这个错误是因为没有定义'__GNUC__'的另一个编译器(oracle),所以sys/cdefs将'__attribute __(X)'定义为空(sunCC提供了它自己的sys/cdefs来避免这种情况)。 – 2014-12-12 17:54:13

+0

我检查了__GNUC__被定义为 – user11869 2014-12-16 19:45:40

+0

@Jonathan Wakely,我从gcc文档中找到了这个“如果目标符号只是通过弱引用引用,那么它将成为一个弱的未定义符号。”我不太明白这句话的意思。但是,这可能是原因吗? – user11869 2014-12-16 19:57:59

相关问题