2014-04-15 114 views
2

我想在Linux 64位機器上用C編譯hello世界程序。我正在使用ARM交叉編譯器將我的應用程序加載到ARM處理器上。但是,使用arm-none-eabi-gcc -o hello hello.c編譯代碼時,我得到了一系列的錯誤:使用arm-none-eabi-gcc編譯hello world程序時出錯編號

/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

當我嘗試做編譯:arm-none-eabi-gcc -c hello.c,它創建了一個目標代碼hello.o告訴我,編譯器運行正常。

有人可能會告訴我爲什麼我的彙編是返回這樣的錯誤嗎?

UPDATE

我現在認識到C運行時庫不包含在彙編。有誰知道我需要包含在編譯中的任何選項,或者如何鏈接庫以便能夠使用標準函數(例如printf)?

+0

外觀http://embdev.net/topic/129753 –

+1

這可能會幫助你http://stackoverflow.com/questions/13235748/linker-error-on-ac-project-using-eclipse –

+0

它缺乏你libc低級函數。它依賴於平臺,所以arm-none-eabi-gcc工具鏈不會擁有它。它通常由芯片製造商提供。目標平臺是什麼? **如果你停止使用libc函數(printf,malloc,open等),你可以編譯你的程序。 –

回答

1

由於沒有控制檯,MCU芯片應該如何處理printf字符串?這就是發生的事情。 libc需要與平臺有關的低級函數,不應包含在libc中。

您需要一個retarget.c或syscalls.c文件來定義所有這些缺失的符號,並正確地將printf輸出重定向到您可以從芯片外部訪問的串行線。

我強烈建議您使用yagarto工具包,它們提供了一個syscall.c文件,其中包含在與libc鏈接時構建項目所需的內容。

如果您想嘗試短路徑,請將syscall.c文件包含到您的項目中,並對其函數內部進行重新編程以滿足您的需求。

將單純的gcc工具鏈鏈接到微控制器世界中的libc並不適合初學者。我的建議是始終按照yagarto的教程逐步進行。

+1

謝謝你的幫助!這個你好世界程序,因此使用打印只是爲了測試工具鏈,以便以後在我的項目中使用。一旦我希望能夠實現它,我將不再使用這些標準功能,而是使用標準庫(uIP)。雖然,您的syscall.c鏈接不起作用。 – Adam

相關問題