本文介绍了未定义的引用错误 _dl_stack_flags 与 gcc 和 pthreads的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在 Ubuntu 上使用 pthreads 编译应用程序时出现以下错误:

I get the following error when trying to compile an application using pthreads on Ubuntu:

/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/libpthread.a(pthread_create.o): In function `allocate_stack':
/build/buildd/eglibc-2.11.1/nptl/allocatestack.c:444: undefined reference to `_dl_stack_flags'

Ubuntu 版本是:

Ubuntu version is:

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 版本是:

wade@wadesworld:~$ gcc -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.3-4ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-plugin --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i486 --with-tune=generic --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5)

构建命令是:

/usr/bin/cmake -E cmake_link_script CMakeFiles/vtest.dir/link.txt
--verbose=1 /usr/bin/c++      CMakeFiles/vtest.dir/certificate.cc.o
CMakeFiles/vtest.dir/client.cc.o CMakeFiles/vtest.dir/vinterface.cc.o
CMakeFiles/vtest.dir/vuser.cc.o CMakeFiles/vtest.dir/config.cc.o
CMakeFiles/vtest.dir/vinterface.cc.o CMakeFiles/vtest.dir/vuser.cc.o
CMakeFiles/vtest.dir/vtest.cc.o CMakeFiles/vtest.dir/interface.cc.o
CMakeFiles/vtest.dir/auth.cc.o CMakeFiles/vtest.dir/main.cc.o
CMakeFiles/vtest.dir/manage.cc.o CMakeFiles/vtest.dir/md5.c.o
CMakeFiles/vtest.dir/mm.cc.o CMakeFiles/vtest.dir/mysqldb.cc.o
CMakeFiles/vtest.dir/process.cc.o CMakeFiles/vtest.dir/server.cc.o
CMakeFiles/vtest.dir/vinterface.cc.o CMakeFiles/vtest.dir/server_instance.cc.o
CMakeFiles/vtest.dir/support.cc.o CMakeFiles/vtest.dir/sysinterface.cc.o
CMakeFiles/vtest.dir/vsuser.cc.o CMakeFiles/vtest.dir/user.cc.o
-o vtest -rdynamic -L/home/wade/vtest/external_dependencies/lin/lib
-Wl,-Bstatic -lmysqlclient -lsqlite3 -lpthread -Wl,-Bdynamic -ldl
-Wl,-Bstatic -lcrypt -Wl,-Bdynamic
-Wl,-rpath,/home/wade/vtest/external_dependencies/lin/lib
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/libpthread.a(
pthread_create.o): In function `allocate_stack':
/build/buildd/eglibc-2.11.1/nptl/allocatestack.c:444: undefined
reference to `_dl_stack_flags'

以前有人解决过这个问题吗?

Has anyone solved this problem before?

推荐答案

这个问题也在 询问 Ubuntu.

简而言之,问题似乎是由于尝试将 libpthread 静态链接到动态 libc.动态链接 libpthread 应该会使错误消失,我怀疑如果 libpthreadlibc 都是静态链接的,错误也会消失.

In short, the problem appears to be due to trying to statically link libpthread against a dynamic libc. Dynamically linking libpthread should make the error go away, and I suspect that the error would also go away if both libpthread and libc were statically linked.

这篇关于未定义的引用错误 _dl_stack_flags 与 gcc 和 pthreads的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-16 00:44