I am trying to compile a hello world program in C on a Linux 64-bit machine. I am using an ARM cross compiler to load my application onto an ARM processor. However, when compiling the code using arm-none-eabi-gcc -o hello hello.c
I get a series of errors:
我正在尝试在一个Linux 64位机器上编译一个hello world程序。我使用ARM交叉编译器将我的应用程序加载到ARM处理器上。但是,当使用arm-none-eabi-gcc -o hello hello编译代码时。c我犯了一系列错误:
/home/dico/gcc-arm-none-eabi-4_7-2013q3/bin/../lib/gcc/arm-none-eabi/4.7.4/../../../../arm-none-eabi/lib/libc.a(lib_a-exit.o): In function
exit': exit.c:(.text.exit+0x2c): undefined reference to
_exit' /home/dico/gcc-arm-none-eabi-4_7-2013q3/bin/../lib/gcc/arm-none-eabi/4.7.4/../../../../arm-none-eabi/lib/libc.a(lib_a-sbrkr.o): In function_sbrk_r': sbrkr.c:(.text._sbrk_r+0x18): undefined reference to
_sbrk' /home/dico/gcc-arm-none-eabi-4_7-2013q3/bin/../lib/gcc/arm-none-eabi/4.7.4/../../../../arm-none-eabi/lib/libc.a(lib_a-writer.o): In function_write_r': writer.c:(.text._write_r+0x20): undefined reference to
_write' /home/dico/gcc-arm-none-eabi-4_7-2013q3/bin/../lib/gcc/arm-none-eabi/4.7.4/../../../../arm-none-eabi/lib/libc.a(lib_a-closer.o): In function_close_r': closer.c:(.text._close_r+0x18): undefined reference to
_close' /home/dico/gcc-arm-none-eabi-4_7-2013q3/bin/../lib/gcc/arm-none-eabi/4.7.4/../../../../arm-none-eabi/lib/libc.a(lib_a-fstatr.o): In function_fstat_r': fstatr.c:(.text._fstat_r+0x1c): undefined reference to
_fstat' /home/dico/gcc-arm-none-eabi-4_7-2013q3/bin/../lib/gcc/arm-none-eabi/4.7.4/../../../../arm-none-eabi/lib/libc.a(lib_a-isattyr.o): In function_isatty_r': isattyr.c:(.text._isatty_r+0x18): undefined reference to
_isatty' /home/dico/gcc-arm-none-eabi-4_7-2013q3/bin/../lib/gcc/arm-none-eabi/4.7.4/../../../../arm-none-eabi/lib/libc.a(lib_a-lseekr.o): In function_lseek_r': lseekr.c:(.text._lseek_r+0x20): undefined reference to
_lseek' /home/dico/gcc-arm-none-eabi-4_7-2013q3/bin/../lib/gcc/arm-none-eabi/4.7.4/../../../../arm-none-eabi/lib/libc.a(lib_a-readr.o): In function_read_r': readr.c:(.text._read_r+0x20): undefined reference to
_read' collect2: error: ld returned 1 exit status/home/dico/gcc -手臂没有eabi - 4 - _7 - 2013第三季度/ bin / . . / lib / gcc / arm-none-eabi / 4.7.4 / . . / . . / . . / . . / arm-none-eabi / lib / libc.a(lib_a-exit.o):在函数退出”:exit.c:(.text.exit + 0 x2c):未定义的参考to_exit”/home/dico/gcc -手臂没有eabi - 4 - _7 - 2013第三季度/ bin / . . / lib / gcc / arm-none-eabi / 4.7.4 / . . / . . / . . / . . / arm-none-eabi / lib / libc.a(lib_a-sbrkr.o):在函数_sbrk_r sbrkr.c:(.text._sbrk_r + 0 x18):未定义的引用to_sbrk' /home/dico/gcc-arm-none-eabi-4_7-2013q3/bin/. /. /. /../../../../ .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..。undefined引用to_close' /home/dico/gcc-arm-none-eabi-4_7-2013q3/bin/. /. /. /../../../../ .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .undefined reference to_isatty' /home/dico/gcc-arm-none-eabi-4_7-2013q3/bin/. /. /. /../../../../ ../.. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..
When I try compiling by doing: arm-none-eabi-gcc -c hello.c
, it creates an object code hello.o
which tells me that the compiler runs fine.
当我尝试编译时:arm-none-eabi-gcc -c hello。它创建了一个对象代码hello。o告诉我编译器运行良好。
Could someone perhaps tell me why my compilation is return such errors please?
有人能告诉我为什么我的编辑会返回这些错误吗?
UPDATE
更新
I realize now that the C runtime library isn't included in the compilation. Does anyone know of any options I need to include in the compilation or how to link the library to be able to use standard functions such as printf for example?
我现在意识到C运行时库不包含在编译中。是否有人知道我需要在编译中包含哪些选项,或者如何链接库以使用诸如printf之类的标准函数?
1 个解决方案
#1
1
What should the MCU chip do with a printf string since there is no console? That's what is happening. libc needs low level functions that is platform dependent and shall not be included in the libc.
由于没有控制台,MCU芯片应该如何处理printf字符串?这就是正在发生的事情。libc需要的是平台依赖的低级别功能,并且不应包含在libc中。
You need a retarget.c or a syscalls.c file that defines all these missing symbols and properly retarget the printf output to a serial line that you have access from the outside of the chip.
你需要一个过程。c或系统调用。c文件定义所有这些缺失的符号,并正确地将printf输出重定向到从芯片外部访问的串行线。
I strongly recommend you to use the yagarto toolkit, they provide a syscall.c file with what's necessary to build a project when linking against libc, as you are doing.
我强烈建议您使用yagarto工具包,它们提供了一个syscall。在与libc链接时,需要构建一个项目的c文件,就像您正在做的那样。
If you want to try the short path, include the syscall.c file to your project and reprogram its functions internals to suit your needs.
如果您想尝试短路径,请包括syscall。c文件到你的项目,并重新规划它的功能内部以满足你的需要。
Linking bare gcc toolchain against libc in the microcontroller world is not for beginners. My recommendation is always to follow step by step yagarto's tutorials.
在microcontroller的世界中,将裸gcc工具链与libc连接起来并不适合初学者。我的建议是始终遵循yagarto的教程。
#1
1
What should the MCU chip do with a printf string since there is no console? That's what is happening. libc needs low level functions that is platform dependent and shall not be included in the libc.
由于没有控制台,MCU芯片应该如何处理printf字符串?这就是正在发生的事情。libc需要的是平台依赖的低级别功能,并且不应包含在libc中。
You need a retarget.c or a syscalls.c file that defines all these missing symbols and properly retarget the printf output to a serial line that you have access from the outside of the chip.
你需要一个过程。c或系统调用。c文件定义所有这些缺失的符号,并正确地将printf输出重定向到从芯片外部访问的串行线。
I strongly recommend you to use the yagarto toolkit, they provide a syscall.c file with what's necessary to build a project when linking against libc, as you are doing.
我强烈建议您使用yagarto工具包,它们提供了一个syscall。在与libc链接时,需要构建一个项目的c文件,就像您正在做的那样。
If you want to try the short path, include the syscall.c file to your project and reprogram its functions internals to suit your needs.
如果您想尝试短路径,请包括syscall。c文件到你的项目,并重新规划它的功能内部以满足你的需要。
Linking bare gcc toolchain against libc in the microcontroller world is not for beginners. My recommendation is always to follow step by step yagarto's tutorials.
在microcontroller的世界中,将裸gcc工具链与libc连接起来并不适合初学者。我的建议是始终遵循yagarto的教程。