[英]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.