gcc 和 pthreads 中未定义引用错误 _dl_stack_flags

gcc 和 pthreads 中未定义引用错误 _dl_stack_flags

在 StackOverflow 上询问,但建议的解决方案涉及使用 gcc 3.4。

问题详细信息:

StackOverflow 上的 _dl_stack_flags_error 问题

但是,我的 Ubuntu 10:

wade@wadesworld:~$ uname -a
Linux wadesworld 2.6.18-194.8.1.el5.028stab070.5ent #1 SMP Fri Sep 17 19:46:02 MSD 2010 i686 GNU/Linux

仅允许最低版本 gcc 4.1。

有谁见过/解决过这个问题吗?

答案1

查看 Stack Overflow 问题中的信息,我认为问题是由于您静态链接造成的libpthread。我整理了以下简单的测试程序:

#include <pthread.h>

static void *
thread_start(void *arg)
{
}

int
main(int argc, char **argv)
{
    pthread_t thread_id = 0;
    void *result = NULL;

    pthread_create(&thread_id, NULL, &thread_start, NULL);
    pthread_join(thread_id, &result);
}

如果我使用 编译它gcc -o test test.c -lpthread,则不会出现任何错误。如果我尝试静态链接线程,但其他所有内容都动态链接,则会收到许多错误,包括缺失_dl_stack_flags错误:

$ gcc -o test test.c -Wl,-Bstatic -lpthread -Wl,-Bdynamic
/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.5.2/../../../libpthread.a(pthread_create.o): In function `allocate_stack':
/build/buildd/eglibc-2.13/nptl/allocatestack.c:451: undefined reference to `_dl_stack_flags'
/build/buildd/eglibc-2.13/nptl/allocatestack.c:595: undefined reference to `_dl_stack_flags'
/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.5.2/../../../libpthread.a(ptw-pause.o): In function `__pause_nocancel':
/build/buildd/eglibc-2.13/nptl/../sysdeps/unix/syscall-template.S:82: undefined reference to `__syscall_error'
/build/buildd/eglibc-2.13/nptl/../sysdeps/unix/syscall-template.S:82: undefined reference to `__syscall_error'
/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.5.2/../../../libpthread.a(nptl-init.o): In function `__pthread_initialize_minimal_internal':
/build/buildd/eglibc-2.13/nptl/nptl-init.c:277: undefined reference to `__libc_setup_tls'
/build/buildd/eglibc-2.13/nptl/nptl-init.c:295: undefined reference to `_dl_cpuclock_offset'
/build/buildd/eglibc-2.13/nptl/nptl-init.c:437: undefined reference to `_dl_init_static_tls'
/build/buildd/eglibc-2.13/nptl/nptl-init.c:439: undefined reference to `_dl_wait_lookup_done'
collect2: ld returned 1 exit status

您没有列出这些额外的错误,但我认为它们也出现在您面前。我怀疑只有当您尝试静态链接libpthread但动态链接时才会发生此错误libc。如果您动态链接,则两者均可行,并且我怀疑如果您静态链接两者,我怀疑这也会起作用。这并不奇怪,因为这两个库相当紧密相关。

因此我建议调整您的构建配置以动态链接libpthread

相关内容