头文件引用缺少导致link错误http://www.robotercoding.com/blog/?p=36
Posted by: roboter in Linux

前些天一个同事碰到一个问题:link出错,是一个很简单的socket程序,代码应该没有什么问题,错误如下:

/usr/lib/gcc/i586-suse-linux/4.1.2/../../../../i586-suse-linux/bin/ld: errno: TLS definition in /lib/libc.so.6 section .tbss mismatches non-TLS reference in \
/tmp/ccox5xu2.o
/lib/libc.so.6: could not read symbols: Bad value

初步表明链接库有问题,使用了non-TLS的引用。而当前的libc使用的应该是TLS,socket代码和当前的环境不一致。但是一般的socket代码也不需要做什么特殊的设置的,感觉很奇怪。google一下,在http://www.opencascade.org/org/forum/thread_9224/中 找到了答案,需要include一个"/usr/include/errno.h"文件即可,但是没有解答原因。找到errno.h文件看了一下,发现在 errno.h中又引用了# include <features.h>,而在features.h中定义了系统的特性。

原来的socket代码就少了一个errno.h文件的引用,加上之后,link通过。


■ qmail-1.03的编译出现问题
../load auto-str substdio.a error.a str.a
/usr/bin/ld: errno: TLS definition in /lib/libc.so.6 section .tbss
mismatches non-TLS reference in substdio.a(substdo.o)
/lib/libc.so.6: could not read symbols: Bad value
collect2: ld returned 1 exit status
make: *** [auto-str] Error 1

后来搜了一下,在哪说的忘记了,是因为gcc版本高了以后对extern int errno这种写法不自动修正了。解决办法:
grep “extern int errno”
把所有grep出来的地方的”extern int errno”换成 #include

试了一下,果然解决。
原文找到了:http://www.webservertalk.com/archive66-2006-3-1441516.html
[bianbian补注]:其实这个错误再打个errno的patch就可以解决的。。。