繁体   English   中英

使用arm-none-eabi-gcc编译hello world program C时出错

[英]Error compiling hello world program C with arm-none-eabi-gcc

我正在尝试在Linux 64位计算机上用C编译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):在函数exit': exit.c:(.text.exit+0x2c): undefined reference to _exit的exit': exit.c:(.text.exit+0x2c): undefined reference to / home / dico / gcc-arm-none -eabi-4_7-2013q3 / bin中/../ LIB / GCC /臂-NONE-EABI / 4.7.4 /../../../../臂-NONE-EABI / LIB /的libc.a( lib_a-sbrkr.o):在函数_sbrk_r': sbrkr.c:(.text._sbrk_r+0x18): undefined reference to _sbrk'/ home / dico / gcc-arm-none-eabi-4_7-2013q3 / bin /的_sbrk_r': sbrkr.c:(.text._sbrk_r+0x18): undefined reference to 。 ./lib/gcc/arm-none-eabi/4.7.4/../../../../arm-none-eabi/lib/libc.a(lib_a-writer.o):在函数_write_r': writer.c:(.text._write_r+0x20): undefined reference to _write的_write_r': writer.c:(.text._write_r+0x20): undefined reference to /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):在函数_close_r': closer.c:(.text._close_r+0x18): undefined reference to _close的_close_r': closer.c:(.text._close_r+0x18): undefined reference to /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):在函数_fstat_r': fstatr.c:(.text._fstat_r+0x1c): undefined reference to _fstat_r': fstatr.c:(.text._fstat_r+0x1c): undefined reference to _fstat的_fstat_r': fstatr.c:(.text._fstat_r+0x1c): undefined reference to /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):在函数_isatty_r': isattyr.c:(.text._isatty_r+0x18): undefined reference to _isatty'/home/dico/gcc _isatty_r': isattyr.c:(.text._isatty_r+0x18): undefined reference to arm-none _isatty_r': isattyr.c:(.text._isatty_r+0x18): undefined reference to eabi-4_7-2013q3/bin/../lib/gcc/arm _isatty_r': isattyr.c:(.text._isatty_r+0x18): undefined reference to none-eabi/4.7.4/../../的_isatty_r': isattyr.c:(.text._isatty_r+0x18): undefined reference to 。 ./../arm-none-eabi/lib/libc.a(lib_a-lseekr.o):在函数_lseek_r': lseekr.c:(.text._lseek_r+0x20): undefined reference to _lseek'/ home /的_lseek_r': lseekr.c:(.text._lseek_r+0x20): undefined reference to迪科/ GCC-臂-NONE-EABI-4_7-2013q3 / bin中/../ LIB / GCC /臂-NONE-EABI / 4.7.4 /../../../../臂-NONE-EABI /lib/libc.a(lib_a-readr.o):在函数_read_r': readr.c:(.text._read_r+0x20): undefined reference to _read'的_read_r': readr.c:(.text._read_r+0x20): undefined reference to collect2:错误:ld返回1退出状态

当我尝试通过以下方式进行编译时: arm-none-eabi-gcc -c hello.c ,它创建了一个目标代码hello.o ,告诉我编译器运行良好。

有人可以告诉我为什么我的编译返回此类错误吗?

UPDATE

现在,我意识到C运行时库未包含在编译中。 有谁知道我需要包含在编译中的任何选项,或者如何链接库才能使用诸如printf之类的标准功能?

由于没有控制台,MCU芯片应如何处理printf字符串? 那就是正在发生的事情。 libc需要依赖于平台的低级功能,并且不应包含在libc中。

您需要一个retarget.c或syscalls.c文件,该文件定义所有这些丢失的符号,并将printf输出正确地重新定向到您可以从芯片外部访问的串行线。

我强烈建议您使用yagarto工具箱,因为它们提供了syscall.c文件,其中包含与libc链接时构建项目所必需的文件,就像您所做的那样。

如果您想尝试短路径,请将syscall.c文件包括到您的项目中,然后重新编程其功能内部以适合您的需求。

在微控制器领域,将裸露的gcc工具链与libc链接起来并不适合初学者。 我的建议是始终遵循yagarto的教程。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM