目前,我正在学习ARM裸机开发。我使用的开发板是SAMA5D3x-EK。
我正在尝试构建Atmel提供的示例代码(Atmel / sama5d3x-ek / examples / getting-started)。
IDE
eclipse with GNU ARM plugin
链接描述文件
Atmel/sama5d3x-ek/libraries/libboard_sama5d3x-ek/resources/gcc/sama5d3x/sram.ld
启动代码
Atmel/sama5d3x-ek/libraries/libboard_sama5d3x-ek/source/board_cstartup_gnu.S
c运行时库存根
Atmel/sama5d3x-ek/libraries/libboard_sama5d3x-ek/source/syscalls.c
我构建了libboard_sama5d3x_ek_gcc_dbg.a
。我非常确定所有存根函数都已打包到.a
静态库中。
$ arm-none-eabi-nm libboard_sama5d3x_ek_gcc_dbg.a
...
syscalls.o:
00000000 T _close
U DBGU_PutChar
00000000 T _exit
00000000 T _fstat
00000000 T _getpid
U _heap
00000000 b heap.9035
U iprintf
00000000 T _isatty
00000000 T _kill
00000000 r .LC0
00000000 T link
00000000 T _lseek
00000000 T _read
00000000 T _sbrk
00000000 T _write
...
但是当我尝试构建项目时,我发现链接器部分存在以下错误:
Building target: arm_sama5d3x_baremetal_template.elf
Invoking: Cross ARM C Linker
arm-none-eabi-gcc -mcpu=cortex-a5 -march=armv7-a -marm -mthumb-interwork -mfloat-abi=hard -mfpu=vfpv4-d16 -O0 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -g3 -T "/home/yusheng/workspace/arm_sama5d3x_baremetal_template/sram.ld" -nostartfiles -Xlinker --gc-sections -L/usr/local/Atmel/sama5d3x-ek/libraries/libchip_sama5d3x/lib -L/usr/local/Atmel/sama5d3x-ek/libraries/libboard_sama5d3x-ek/lib -Wl,-Map,"arm_sama5d3x_baremetal_template.map" -v -static -o "arm_sama5d3x_baremetal_template.elf" ./board_cstartup_gnu.o ./main.o /usr/local/Atmel/sama5d3x-ek/libraries/libboard_sama5d3x-ek/lib/libboard_sama5d3x_ek_gcc_dbg.a /usr/local/Atmel/sama5d3x-ek/libraries/libchip_sama5d3x/lib/libchip_sama5d3x_gcc_dbg.a -lboard_sama5d3x_ek_gcc_dbg -lchip_sama5d3x_gcc_dbg
Using built-in specs.
COLLECT_GCC=arm-none-eabi-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-none-eabi/4.8.2/lto-wrapper
Target: arm-none-eabi
Configured with: ../gcc-4.8.2/configure --build=i686-linux-gnu --prefix=/usr --includedir='/usr/lib/include' --mandir='/usr/lib/share/man' --infodir='/usr/lib/share/info' --sysconfdir=/etc --localstatedir=/var --libexecdir='/usr/lib/lib/gcc-arm-none-eabi' --disable-maintainer-mode --disable-dependency-tracking --enable-languages=c,c++ --prefix=/usr/lib --infodir=/usr/share/doc/gcc-arm-none-eabi/info --mandir=/usr/share/man --htmldir=/usr/share/doc/gcc-arm-none-eabi/html --pdfdir=/usr/share/doc/gcc-arm-none-eabi/pdf --bindir=/usr/bin --libexecdir=/usr/lib --libdir=/usr/lib --with-system-zlib --enable-multilib --disable-decimal-float --disable-libffi --disable-libgomp --disable-libmudflap --disable-libquadmath --disable-libssp --disable-libstdcxx-pch --disable-libstdc++-v3 --disable-nls --disable-shared --disable-threads --disable-tls --disable-plugin --build=i686-linux-gnu --host=i686-linux-gnu --target=arm-none-eabi --with-gnu-as --with-gnu-ld --with-headers=no --without-newlib --with-pkgversion=4.8.2-14ubuntu1+6 --without-included-gettext --with-multilib-list=armv6-m,armv7-m,armv7e-m,armv7-r CFLAGS='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat' CPPFLAGS=-D_FORTIFY_SOURCE=2 CXXFLAGS='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat' FFLAGS='-g -O2' LDFLAGS=-Wl,-z,relro AR_FOR_TARGET=arm-none-eabi-ar AS_FOR_TARGET=arm-none-eabi-as LD_FOR_TARGET=arm-none-eabi-ld NM_FOR_TARGET=arm-none-eabi-nm OBJDUMP_FOR_TARGET=arm-none-eabi-objdump RANLIB_FOR_TARGET=arm-none-eabi-ranlib READELF_FOR_TARGET=arm-none-eabi-readelf STRIP_FOR_TARGET=arm-none-eabi-strip
Thread model: single
gcc version 4.8.2 (4.8.2-14ubuntu1+6)
COMPILER_PATH=/usr/lib/gcc/arm-none-eabi/4.8.2/:/usr/lib/gcc/arm-none-eabi/4.8.2/:/usr/lib/gcc/arm-none-eabi/:/usr/lib/gcc/arm-none-eabi/4.8.2/:/usr/lib/gcc/arm-none-eabi/:/usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/bin/
LIBRARY_PATH=/usr/lib/gcc/arm-none-eabi/4.8.2/armv7-ar/thumb/fpu/:/usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/lib/armv7-ar/thumb/fpu/:/usr/lib/gcc/arm-none-eabi/4.8.2/:/usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/lib/
COLLECT_GCC_OPTIONS='-mcpu=cortex-a5' '-march=armv7-a' '-marm' '-mthumb-interwork' '-mfloat-abi=hard' '-mfpu=vfpv4-d16' '-O0' '-fmessage-length=0' '-fsigned-char' '-ffunction-sections' '-fdata-sections' '-g3' '-T' '/home/yusheng/workspace/arm_sama5d3x_baremetal_template/sram.ld' '-nostartfiles' '-L/usr/local/Atmel/sama5d3x-ek/libraries/libchip_sama5d3x/lib' '-L/usr/local/Atmel/sama5d3x-ek/libraries/libboard_sama5d3x-ek/lib' '-v' '-static' '-o' 'arm_sama5d3x_baremetal_template.elf'
/usr/lib/gcc/arm-none-eabi/4.8.2/collect2 -Bstatic -X -o arm_sama5d3x_baremetal_template.elf -L/usr/local/Atmel/sama5d3x-ek/libraries/libchip_sama5d3x/lib -L/usr/local/Atmel/sama5d3x-ek/libraries/libboard_sama5d3x-ek/lib -L/usr/lib/gcc/arm-none-eabi/4.8.2/armv7-ar/thumb/fpu -L/usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/lib/armv7-ar/thumb/fpu -L/usr/lib/gcc/arm-none-eabi/4.8.2 -L/usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/lib --gc-sections -Map arm_sama5d3x_baremetal_template.map ./board_cstartup_gnu.o ./main.o /usr/local/Atmel/sama5d3x-ek/libraries/libboard_sama5d3x-ek/lib/libboard_sama5d3x_ek_gcc_dbg.a /usr/local/Atmel/sama5d3x-ek/libraries/libchip_sama5d3x/lib/libchip_sama5d3x_gcc_dbg.a -lboard_sama5d3x_ek_gcc_dbg -lchip_sama5d3x_gcc_dbg --start-group -lgcc -lg -lc --end-group -T /home/yusheng/workspace/arm_sama5d3x_baremetal_template/sram.ld
/usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/lib/armv7-ar/thumb/fpu/libg.a(lib_a-init.o): In function `__libc_init_array':
/build/buildd/newlib-2.1.0/build/arm-none-eabi/armv7-ar/thumb/fpu/newlib/libc/misc/../../../../../../../../newlib/libc/misc/init.c:37: undefined reference to `_init'
/usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/lib/armv7-ar/thumb/fpu/libg.a(lib_a-abort.o): In function `abort':
/build/buildd/newlib-2.1.0/build/arm-none-eabi/armv7-ar/thumb/fpu/newlib/libc/stdlib/../../../../../../../../newlib/libc/stdlib/abort.c:63: undefined reference to `_exit'
/usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/lib/armv7-ar/thumb/fpu/libg.a(lib_a-sbrkr.o): In function `_sbrk_r':
/build/buildd/newlib-2.1.0/build/arm-none-eabi/armv7-ar/thumb/fpu/newlib/libc/reent/../../../../../../../../newlib/libc/reent/sbrkr.c:58: undefined reference to `_sbrk'
/usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/lib/armv7-ar/thumb/fpu/libg.a(lib_a-signalr.o): In function `_kill_r':
/build/buildd/newlib-2.1.0/build/arm-none-eabi/armv7-ar/thumb/fpu/newlib/libc/reent/../../../../../../../../newlib/libc/reent/signalr.c:61: undefined reference to `_kill'
/usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/lib/armv7-ar/thumb/fpu/libg.a(lib_a-signalr.o): In function `_getpid_r':
/build/buildd/newlib-2.1.0/build/arm-none-eabi/armv7-ar/thumb/fpu/newlib/libc/reent/../../../../../../../../newlib/libc/reent/signalr.c:96: undefined reference to `_getpid'
/usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/lib/armv7-ar/thumb/fpu/libg.a(lib_a-writer.o): In function `_write_r':
/build/buildd/newlib-2.1.0/build/arm-none-eabi/armv7-ar/thumb/fpu/newlib/libc/reent/../../../../../../../../newlib/libc/reent/writer.c:58: undefined reference to `_write'
/usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/lib/armv7-ar/thumb/fpu/libg.a(lib_a-closer.o): In function `_close_r':
/build/buildd/newlib-2.1.0/build/arm-none-eabi/armv7-ar/thumb/fpu/newlib/libc/reent/../../../../../../../../newlib/libc/reent/closer.c:53: undefined reference to `_close'
/usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/lib/armv7-ar/thumb/fpu/libg.a(lib_a-fstatr.o): In function `_fstat_r':
/build/buildd/newlib-2.1.0/build/arm-none-eabi/armv7-ar/thumb/fpu/newlib/libc/reent/../../../../../../../../newlib/libc/reent/fstatr.c:62: undefined reference to `_fstat'
/usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/lib/armv7-ar/thumb/fpu/libg.a(lib_a-isattyr.o): In function `_isatty_r':
/build/buildd/newlib-2.1.0/build/arm-none-eabi/armv7-ar/thumb/fpu/newlib/libc/reent/../../../../../../../../newlib/libc/reent/isattyr.c:58: undefined reference to `_isatty'
/usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/lib/armv7-ar/thumb/fpu/libg.a(lib_a-lseekr.o): In function `_lseek_r':
/build/buildd/newlib-2.1.0/build/arm-none-eabi/armv7-ar/thumb/fpu/newlib/libc/reent/../../../../../../../../newlib/libc/reent/lseekr.c:58: undefined reference to `_lseek'
/usr/lib/gcc/arm-none-eabi/4.8.2/../../../arm-none-eabi/lib/armv7-ar/thumb/fpu/libg.a(lib_a-readr.o): In function `_read_r':
/build/buildd/newlib-2.1.0/build/arm-none-eabi/armv7-ar/thumb/fpu/newlib/libc/reent/../../../../../../../../newlib/libc/reent/readr.c:58: undefined reference to `_read'
collect2: error: ld returned 1 exit status
make: *** [arm_sama5d3x_baremetal_template.elf] Error 1
错误声称无法找到存根函数,但函数位于静态库中,我已将其添加到项目中。
如果有人能给我一些建议,我将不胜感激。感谢。
@Valeri Atamaniouk
/usr/lib/gcc/arm-none-eabi/4.8.2/collect2
命令的选项由eclipse生成。我不知道如何更改此静态链接顺序。
同样如选项列表中所示,链接顺序如下:
./board_cstartup_gnu.o ./main.o /usr/local/Atmel/sama5d3x-ek/libraries/libboard_sama5d3x-ek/lib/libboard_sama5d3x_ek_gcc_dbg.a /usr/local/Atmel/sama5d3x-ek/libraries/libchip_sama5d3x/lib/libchip_sama5d3x_gcc_dbg.a -lboard_sama5d3x_ek_gcc_dbg -lchip_sama5d3x_gcc_dbg --start-group -lgcc -lg -lc --end-group
在这里,我不知道newlib库的位置。假设newlib库被称为“-lgcc -lg -lc
”,我们应该看到libboard_sama5d3x_ek_gcc_dbg.a
首先出现在它们之前。
我有一个解决方法。重建除syscalls.c
和board_cstartup_gnu.S
之外的静态库。然后复制并将源文件包含到项目中。虽然解决方法有效,但我想了解问题的来源,以及解决此问题的正确方法。
答案 0 :(得分:0)
将您的图书馆放在--start-group
和--end-group
标记之间的某个位置。很可能你有一个案例,当不同的库互相引用时,库组是如何解决的。
答案 1 :(得分:0)
你可以在命令行中尝试以下两个标志(一次一个),这将解决未解决的init问题。
-Xlinker --specs=nosys.specs
-Xlinker --specs=rdimon.specs
其余问题与库和目标文件之前和之后的-Xlinker --start-group和-Xlinker --end-group相关(如上所述)
PS:我希望这能解决你的问题