Looking at the information in your Stack Overflow question, I believe that the problem is due to you statically linking libpthread
. I put together the following trivial test program:
#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);
}
If I compile it with gcc -o test test.c -lpthread
, I get no errors. If I attempt to link thread statically but everything else dynamically, I get a number of errors including the missing _dl_stack_flags
error:
$ 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
You didn't list those additional errors, but I assume they showed up for you too. I suspect that this error only occurs if you try to statically link libpthread
but dynamically link libc
. If you dynamically link both things work, and I suspect that if you statically link both I suspect that would work too. This isn't that surprising, since the two libraries are fairly closely related.
So I'd suggest adjusting your build configuration to dynamically link libpthread
.