1.关于GCC编译问题:
huge.bin(.text+0x0): In function `_start':
: multiple definition of `_start'
2.这种问题,碰到很多次了, 因为是新手,这样就给我带来了很大的麻烦!
3.编译虽然成功了 但是 通过arm-linux-gcc -v huge.bin 来观察 就出现了这么多的错误提示! 真不知道该如何是好!
下面贴出全部的 编译信息:
book@book-desktop:~/TQ2440/huge/build/exes$
book@book-desktop:~/TQ2440/huge/build/exes$ arm-linux-gcc -v huge.bin
Reading specs from /work/tools/gcc-3.4.5-glibc-2.3.6/lib/gcc/arm-linux/3.4.5/specs
Configured with: /work/tools/create_crosstools/crosstool-0.43/build/arm-linux/gcc-3.4.5-glibc-2.3.6/gcc-3.4.5/configure --target=arm-linux --host=i686-host_pc-linux-gnu --prefix=/work/tools/gcc-3.4.5-glibc-2.3.6 --with-float=soft --with-headers=/work/tools/gcc-3.4.5-glibc-2.3.6/arm-linux/include --with-local-prefix=/work/tools/gcc-3.4.5-glibc-2.3.6/arm-linux --disable-nls --enable-threads=posix --enable-symvers=gnu --enable-__cxa_atexit --enable-languages=c,c++ --enable-shared --enable-c99 --enable-long-long
Thread model: posix
gcc version 3.4.5
/work/tools/gcc-3.4.5-glibc-2.3.6/libexec/gcc/arm-linux/3.4.5/collect2 --eh-frame-hdr -dynamic-linker /lib/ld-linux.so.2 -X -m armelf_linux -p /work/tools/gcc-3.4.5-glibc-2.3.6/lib/gcc/arm-linux/3.4.5/../../../../arm-linux/lib/crt1.o /work/tools/gcc-3.4.5-glibc-2.3.6/lib/gcc/arm-linux/3.4.5/../../../../arm-linux/lib/crti.o /work/tools/gcc-3.4.5-glibc-2.3.6/lib/gcc/arm-linux/3.4.5/crtbegin.o -L/work/tools/gcc-3.4.5-glibc-2.3.6/lib/gcc/arm-linux/3.4.5 -L/work/tools/gcc-3.4.5-glibc-2.3.6/lib/gcc/arm-linux/3.4.5/../../../../arm-linux/lib huge.bin -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /work/tools/gcc-3.4.5-glibc-2.3.6/lib/gcc/arm-linux/3.4.5/crtend.o /work/tools/gcc-3.4.5-glibc-2.3.6/lib/gcc/arm-linux/3.4.5/../../../../arm-linux/lib/crtn.o
collect2: ld terminated with signal 11 [Segmentation fault]
huge.bin(.text+0x0): In function `_start':
: multiple definition of `_start'
/work/tools/gcc-3.4.5-glibc-2.3.6/lib/gcc/arm-linux/3.4.5/../../../../arm-linux/lib/crt1.o(.text+0x0): first defined here
huge.bin(.fini+0x0):/work/tools/create_crosstools/crosstool-0.43/build/arm-linux/gcc-3.4.5-glibc-2.3.6/build-glibc/csu/crti.S:52: multiple definition of `_fini'
/work/tools/gcc-3.4.5-glibc-2.3.6/lib/gcc/arm-linux/3.4.5/../../../../arm-linux/lib/crti.o(.fini+0x0):/work/tools/create_crosstools/crosstool-0.43/build/arm-linux/gcc-3.4.5-glibc-2.3.6/build-glibc/csu/crti.S:13: first defined here
huge.bin(.got+0x0): multiple definition of `_GLOBAL_OFFSET_TABLE_'
/work/tools/gcc-3.4.5-glibc-2.3.6/lib/gcc/arm-linux/3.4.5/../../../../arm-linux/lib/crti.o(.got.plt+0x0): first defined here
huge.bin(.rodata+0x0): multiple definition of `_IO_stdin_used'
/work/tools/gcc-3.4.5-glibc-2.3.6/lib/gcc/arm-linux/3.4.5/../../../../arm-linux/lib/crt1.o(.rodata+0x0): first defined here
huge.bin(.data+0x0): In function `__data_start':
: multiple definition of `__data_start'
/work/tools/gcc-3.4.5-glibc-2.3.6/lib/gcc/arm-linux/3.4.5/../../../../arm-linux/lib/crt1.o(.data+0x0): first defined here
huge.bin(.data+0x4): In function `__data_start':
: multiple definition of `__dso_handle'
/work/tools/gcc-3.4.5-glibc-2.3.6/lib/gcc/arm-linux/3.4.5/crtbegin.o(.data+0x0): first defined here
huge.bin(.init+0x0):/work/tools/create_crosstools/crosstool-0.43/build/arm-linux/gcc-3.4.5-glibc-2.3.6/build-glibc/csu/crti.S:37: multiple definition of `_init'
/work/tools/gcc-3.4.5-glibc-2.3.6/lib/gcc/arm-linux/3.4.5/../../../../arm-linux/lib/crti.o(.init+0x0): first defined here
/work/tools/gcc-3.4.5-glibc-2.3.6/lib/gcc/arm-linux/3.4.5/../../../../arm-linux/lib/crti.o(.dynamic+0x0): multiple definition of `_DYNAMIC'
huge.bin(.dynamic+0x0): first defined here
3.只能求助论坛了:
估计是动态链接的原因!
-l name 在连接时使用函数库libname.a,连接程序在-Ldir选项指定的目录下和/lib,/usr/lib目录下寻找该库文件。在没有使用-static选项时,如果发现共享函数库libname.so,则使用libname.so进行动态连接。
-static 禁止与共享函数库连接。
-shared 尽量与共享函数库连接
date:2012-10-26
2013-4-22:来自StudyOS的链接不成功报错:
arm-linux-ld -Bstatic -T /home/book/TQ2440/StudyOS/startup/StudyOS.lds -o StudyOS /home/book/TQ2440/StudyOS/startup/libstartup.a /home/book/TQ2440/StudyOS/major/libmain.a /home/book/TQ2440/StudyOS/drivers/strings/libstrings.a /home/book/TQ2440/StudyOS/drivers/interrupt/libinterrupt.a /home/book/TQ2440/StudyOS/drivers/hardware/libhardware.a /home/book/TQ2440/StudyOS/drivers/general/libgeneral.a /home/book/TQ2440/StudyOS/drivers/fontlibrary/libfontlibrary.a /home/book/TQ2440/StudyOS/memory/libmemory.a /home/book/TQ2440/StudyOS/application/libapp.a \
-L /work/tools/gcc-3.4.5-glibc-2.3.6/lib/gcc/arm-linux/3.4.5 -lgcc\
-Map StudyOS.map -o StudyOS
/home/book/TQ2440/StudyOS/major/libmain.a(main.o)(.data+0x44): multiple definition of `BOOTINFO'
startup/nand.o(.data+0x0): first defined here
/home/book/TQ2440/StudyOS/drivers/interrupt/libinterrupt.a(interrupt.o)(.data+0x84): multiple definition of `BOOTINFO'
startup/nand.o(.data+0x0): first defined here
/home/book/TQ2440/StudyOS/drivers/hardware/libhardware.a(lcddriver.o)(.data+0x18): multiple definition of `BOOTINFO'
startup/nand.o(.data+0x0): first defined here
/home/book/TQ2440/StudyOS/drivers/hardware/libhardware.a(lcdappl.o)(.data+0x0): multiple definition of `BOOTINFO'
startup/nand.o(.data+0x0): first defined here
/home/book/TQ2440/StudyOS/drivers/hardware/libhardware.a(mouse.o)(.data+0x0): multiple definition of `BOOTINFO'
startup/nand.o(.data+0x0): first defined here
/home/book/TQ2440/StudyOS/drivers/hardware/libhardware.a(touch_screen.o)(.data+0x0): multiple definition of `BOOTINFO'
startup/nand.o(.data+0x0): first defined here
/home/book/TQ2440/StudyOS/drivers/hardware/libhardware.a(tc_correct.o)(.data+0x0): multiple definition of `BOOTINFO'
startup/nand.o(.data+0x0): first defined here
/home/book/TQ2440/StudyOS/drivers/hardware/libhardware.a(timer.o)(.data+0x0): multiple definition of `BOOTINFO'
startup/nand.o(.data+0x0): first defined here
make: *** [StudyOS] Error 1
PS:这种在编译的时候能够成功,但链接不成功的例子,在我们 Linux 环境编译下,已经不是第一次了.
下面我们来贴一下源代码中 BOOTINFO 的定义及引用文件 :
结构体原型:
struct BOOT
{
U8 cyls,leds,vmode,reserve;
U16 scrn_x,scrn_y;
U16 *vram;
}BOOTINFO = {0,0,0,0,480,272,NULL};
用到这个变量的文件夹:
Struct.h (include):typedef struct BOOT BOOT_INFO;
Lcdappl.c (drivers\hardware):static BOOT_INFO *bootinfo;
Lcddriver.c (drivers\hardware): static BOOT_INFO *bootinfo = (BOOT_INFO *)&BOOTINFO;
Mouse.c (drivers\hardware): static BOOT_INFO *bootinfo;
Tc_correct.c (drivers\hardware): static BOOT_INFO *bootinfo;
Touch_screen.c (drivers\hardware): static BOOT_INFO *bootinfo = (BOOT_INFO *)&BOOTINFO;
PS:综上,如果是比较大的项目,笔者建议采用第二种 方法, 一是便于“维护”,二是“可读性性”比较好.
由于笔者刚开始没有使用第二种方法,导致后来项目无法写下去了,而且很难修改,动不动就报错.
所以前面的错误也迎刃而解了。
转载:http://blog.sina.com.cn/s/blog_87c063060101bmtt.html