Chinaunix首页 | 论坛 | 博客
  • 博客访问: 353380
  • 博文数量: 49
  • 博客积分: 3229
  • 博客等级: 中校
  • 技术积分: 616
  • 用 户 组: 普通用户
  • 注册时间: 2006-11-26 21:46
文章分类

全部博文(49)

文章存档

2011年(8)

2010年(2)

2009年(3)

2008年(36)

我的朋友

分类:

2008-12-25 16:09:37

用2.95.3的arm_linux_gcc编译vivi时出现以下问题:

/usr/local/arm/2.95.3/bin/arm-linux-ld -v -Tarch/vivi.lds -Bstatic \

  arch/s3c2410/head.o \
  arch/s3c2410/s3c2410.o init/main.o init/version.o lib/lib.o \
  lib/priv_data/priv_data.o \
  usb/usb.o drivers/serial/serial.o drivers/mtd/mtd.o \
  -o vivi-elf -L/usr/local/arm/2.95.3/lib/gcc-lib/arm-linux/2.95.3 -L/usr/local/arm/2.95.3/arm-linux/lib -lgcc -lc
GNU ld version 2.11.2 (with BFD 2.11.2)
/usr/local/arm/2.95.3/arm-linux/lib/libc.a(_itoa.o):???'_itoa'?:
/tmp/cross/src/glibc-2.2.3/stdio-common/_itoa.c:284: undefined reference to `__lshrdi3'
/tmp/cross/src/glibc-2.2.3/stdio-common/_itoa.c:285: undefined reference to `__lshrdi3'
/tmp/cross/src/glibc-2.2.3/stdio-common/_itoa.c:338: undefined reference to `__ashldi3'
/usr/local/arm/2.95.3/arm-linux/lib/libc.a(_itowa.o):???'_itowa'?:
/tmp/cross/src/glibc-2.2.3/stdio-common/_itowa.c:208: undefined reference to `__lshrdi3'
/tmp/cross/src/glibc-2.2.3/stdio-common/_itowa.c:209: undefined reference to `__lshrdi3'
/tmp/cross/src/glibc-2.2.3/stdio-common/_itowa.c:262: undefined reference to `__ashldi3'
/usr/local/arm/2.95.3/arm-linux/lib/libc.a(profil.o):???'profil_counter'?:
/tmp/cross/src/glibc-2.2.3/gmon/../sysdeps/posix/profil.c:43: undefined reference to `__muldi3'
/usr/local/arm/2.95.3/arm-linux/lib/libc.a(strtoll.o):???'__strtoll_internal'?:
/tmp/cross/src/glibc-2.2.3/stdlib/../sysdeps/generic/strtol.c:386: undefined reference to `__udivdi3'
/tmp/cross/src/glibc-2.2.3/stdlib/../sysdeps/generic/strtol.c:387: undefined reference to `__umoddi3'
/tmp/cross/src/glibc-2.2.3/stdlib/../sysdeps/generic/strtol.c:485: undefined reference to `__muldi3'
/usr/local/arm/2.95.3/arm-linux/lib/libc.a(strtoull.o):???'__strtoull_internal'?:
/tmp/cross/src/glibc-2.2.3/stdlib/../sysdeps/generic/strtol.c:386: undefined reference to `__udivdi3'
/tmp/cross/src/glibc-2.2.3/stdlib/../sysdeps/generic/strtol.c:387: undefined reference to `__umoddi3'
/tmp/cross/src/glibc-2.2.3/stdlib/../sysdeps/generic/strtol.c:485: undefined reference to `__muldi3'

make: *** [vivi] 错误 1

出现

undefined reference to `__lshrdi3'

undefined reference to `__udivdi3'

undefined reference to `__muldi3'

这种错误大概就是没有包含libgcc.a库。可我这里明确指定了库的路径以及库名,却还是有问题。。无意间把编译选项-lgcc -lc改为-lc -lgcc后问题解决。。。

后来在http://www.linuxexpress.com.cn/news/dev/2008-06-06/1745.html找到了一些依据。先抄录如下:

将多个.o文件链接成可执行文件的时候。如果链接的顺序不对,会产生错误。
《An introduction of gcc》里面有下面一段话:
On Unix-like systems, the traditional behavior of compilers and linkers
is to search for external functions from left to right in the object files
specified on the command line. This means that the object file which
contains the definition of a function should appear after any files which
call that function.

但是也说了:
Most current compilers and linkers will search all object files, regardless
of order, but since not all compilers do this it is best to follow the
convention of ordering object files from left to right.

链接库的时候,也存在这个问题。
今天写程序做了一下试验,发现gcc和我现在用的一个板子的编译器都可以不用严格按照顺序。
但是同时发现了另一个问题,就是我们自己的操作系统提供的库文件有两个:libgcc.a和libcs.a。
链接的时候要加上 -lcs -lgcc ,如果这两个顺序搞乱了,就会报错。

xscale-elf-ld -L../../lib -o main test1.o test2.o main.o /
-lgcc /
-lcs
xscale-elf-ld: warning: cannot find entry symbol _start; defaulting to 00008000
../../lib/libcs.a(_uprint.o): In function `outnum':
_uprint.o(.text+0x1ac): undefined reference to `__modsi3'
_uprint.o(.text+0x1c8): undefined reference to `__divsi3'
../../lib/libcs.a(_uprint.o): In function `outnum_u':
_uprint.o(.text+0x2e0): undefined reference to `__umodsi3'
_uprint.o(.text+0x2f4): undefined reference to `__udivsi3'
../../lib/libcs.a(fvwrite.o): In function `__sfvwrite':
fvwrite.o(.text+0x270): undefined reference to `__udivsi3'
make.exe: *** [main] Error 1

为什么编译器在搜索目标文件的时候可以不看顺序,搜索库文件的时候却会报错呢?


下面是hh的解答:
不依命令行的顺序的话就得重复扫描目标文件,我猜可能是重复扫描库文件的开销比较大所以必须在命令行指定正确的顺序。海东有空也可读读此书:


我认为很有道理。




阅读(4484) | 评论(0) | 转发(0) |
0

上一篇:贾谊论

下一篇:vivi的usb下载移植成功

给主人留下些什么吧!~~