带有gcc和pthreads的未定义引用错误_dl_stack_flags

时间:2011-04-21 00:00:52

标签: gcc ubuntu pthreads

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

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

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'

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

1 个答案:

答案 0 :(得分:5)

此问题也在Ask Ubuntu上提出。

简而言之,问题似乎是由于尝试将libpthread静态链接到动态libc。动态链接libpthread会导致错误消失,我怀疑如果libpthreadlibc静态链接,错误也会消失。