使用arm-none-eabi-gcc和链接库liba进行编译。一个错误

时间:2022-09-14 15:29:41

I am compiling a hello world program in C on a 64-bit Linux machine. I am using a GCC ARM embedded toolchain to cross compile my program on a FOX G20 V board with an ATMEL AT91SAM9G20 processor.

我正在一个64位的Linux机器上编译一个hello world程序。我使用的是GCC ARM嵌入式工具链,通过ATMEL AT91SAM9G20处理器,在福克斯G20 V板上交叉编译我的程序。

On the first take, I had a few errors when compiling because the program didn't recognize the printf, return etc. functions (the standard C functions). So I decided to make the link between the functions, which I believe are defined in the libc.a library (correct me if I'm wrong), by doing arm-none-eabi-gcc -o hello hello.c libc.a but the outcome still results in errors:

首先,在编译时我有一些错误,因为程序没有识别printf、return等函数(标准C函数)。所以我决定在函数之间建立联系,我认为这是在libc中定义的。一个图书馆(如果我错了,请纠正我),通过做arm-none-eabi-gcc -o hello hello。c libc。a但是结果仍然会导致错误:

libc.a(lib_a-exit.o): In function `exit':
exit.c:(.text.exit+0x16): undefined reference to `_exit'
libc.a(lib_a-sbrkr.o): In function `_sbrk_r':
sbrkr.c:(.text._sbrk_r+0xc): undefined reference to `_sbrk'
libc.a(lib_a-writer.o): In function `_write_r':
writer.c:(.text._write_r+0x10): undefined reference to `_write'
libc.a(lib_a-closer.o): In function `_close_r':
closer.c:(.text._close_r+0xc): undefined reference to `_close'
libc.a(lib_a-fstatr.o): In function `_fstat_r':
fstatr.c:(.text._fstat_r+0xe): undefined reference to `_fstat'
libc.a(lib_a-isattyr.o): In function `_isatty_r':
isattyr.c:(.text._isatty_r+0xc): undefined reference to `_isatty'
libc.a(lib_a-lseekr.o): In function `_lseek_r':
lseekr.c:(.text._lseek_r+0x10): undefined reference to `_lseek'
libc.a(lib_a-readr.o): In function `_read_r':
readr.c:(.text._read_r+0x10): undefined reference to `_read'
collect2: error: ld returned 1 exit status

I'm really unsure as to why the program still does not recognize the standard functions even though I've linked the library to the application. If anyone has a reason as to why, or a solution as to how I can fix this problem, I would be very grateful.

我很不确定为什么程序仍然不能识别标准函数,尽管我已经将库链接到应用程序。如果有人有理由解释为什么,或者解决这个问题的方法,我会非常感激。

UPDATE

更新

I've downloaded the glibc library from here. I've compiled and created a static library from the syscalls.c library that I found in newlib-2.1.0/libgloss/arm and when I link the library to my application code, I still get the same error.

我从这里下载了glibc库。我已经编译并创建了一个来自syscalls的静态库。我在newlib-2.1.0/libgloss/arm中找到的c库,当我将库链接到我的应用程序代码时,仍然会得到相同的错误。

1 个解决方案

#1


15  

Try executing this:

尝试执行:

arm-none-eabi-gcc --specs=rdimon.specs -lgcc -lc -lm -lrdimon -o hello hello.c

Your toolkit seems to provide the librdimon.a, a library which provides the basic standard C functions.

您的工具箱似乎提供了librdimon。一个提供基本标准C函数的库。

#1


15  

Try executing this:

尝试执行:

arm-none-eabi-gcc --specs=rdimon.specs -lgcc -lc -lm -lrdimon -o hello hello.c

Your toolkit seems to provide the librdimon.a, a library which provides the basic standard C functions.

您的工具箱似乎提供了librdimon。一个提供基本标准C函数的库。