undefined reference to `__assert_fail'

今天同事问了我一个关于DD-WRT编译的问题,在link里面一个工具的时候出现了下面的错误:

 

[root@localhost dhcpforwarder]# mipsel-linux-uclibc-gcc -o dhcpfwd -ffunction-sections -fdata-sections -Wl,--gc-sections src/parser.o src/main.o src/cfg.o src/recvfromflags.o src/output.o

/home/ipdslam_users/yzeng/dd-wrt/toolchains/4.1.0-uclibc-0.9.28/bin/../lib/gcc/mipsel-linux-uclibc/4.1.0/../../../../mipsel-linux-uclibc/bin/ld: BFD 2.16.1 assertion fail /home/openwrt/trunk/openwrt/toolchain_build_mipsel/binutils-2.16.1/bfd/elfxx-mips.c:2562

src/main.o: In function `execRelay':

main.c:(.text+0x590): undefined reference to `__assert_fail'

main.c:(.text+0x690): undefined reference to `__assert_fail'

src/main.o: In function `determineMaxMTU':

main.c:(.text+0x914): undefined reference to `__assert_fail'

main.c:(.text+0x970): undefined reference to `__assert_fail'

src/main.o: In function `fillFDSet':

main.c:(.text+0xb4c): undefined reference to `__assert_fail'

src/main.o:main.c:(.text+0xbd4): more undefined references to `__assert_fail' follow

collect2: ld returned 1 exit status

 

我在

http://lists.busybox.net/pipermail/uclibc/2002-February/002657.html

上看到了这样一些描述:

 

On Sun Feb 17, 2002 at 10:49:59PM -0600, Alberto Alonso wrote:
> When trying to compile a program that uses the
> microwindows library I get the following error:
>
> nxproto.o(.text+0x13f): undefined reference to `__assert_fail'
> nxproto.o(.text+0x169): undefined reference to `__assert_fail'
>
> After doing some grepping I did see an assert function
> Could I use that one instead?
 
I think you must be mixing code compiled with glibc with code
compiled with uClibc, since glibc defines __assert_fail in
include/assert.h and #defines assert to call that, while uClibc
does not use or define __assert_fail at all...  Check that you
are not mixing libraries compiled with glibc with code compiled
with uClibc....
 
 -Erik

 

尝试清除了src/parser.o src/main.o src/cfg.o src/recvfromflags.o src/output.o这几个目标文件再去编译,发现链接成功了。

最后我们发现,在该主机上装了一个MontaVista 3.1 Pro的环境,而且PATH和CROSS_COMPILE这2个环境,默认都指向了MV,所以开始的时候的确有一部分是用MV的交叉编译器来编译的,后面修改过环境变量。因为MV里用的是Glibc的环境,所以就有了上面的错误。

 

我觉得我们在写一个编译脚本的时候,最好能够清除默认的一些环境变量,将本代码需要的环境导出。这样就不会因为在一台服务器上安装了太多的环境导致混乱。

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值