Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling using arm-none-eabi-gcc and linking library liba.a error

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.

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:

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.

like image 416
Adam Avatar asked Apr 16 '14 07:04

Adam


People also ask

What is ARM EABI GCC?

This is an ARM gcc toolchain for cortex M0 and M3. The configuration is optimal for ARM 7, 9, and Cortex processors running in an embedded mode (with no OS). The binaries include the following: Binary. Version.

What means none Eabi?

arm-none-eabi: This toolchain targets the ARM architecture, has no vendor, does not target any operating system, and complies with the ARM EABI.

What specs Nosys?

For example, nosys. specs just defines that system calls should be implemented as stubs that return errors when called ( -lnosys ). The choice of libc in this case depends on whether nano should be used. With %G the libgcc spec-string is processed, which defines the parameters passed to the linker.


Video Answer


2 Answers

I got this error because my binary cannot fit the ROM.

My first error was:

address 0x34000 of arm_flash.elf section `.mmu_tbl' is not within region `ps7_ram_0`

Then I've got the same list of undefined reference errors.

I need to reduce the binary size, by removing new keywords, and all dynamic memory allocation from my C++ code.

like image 71
betontalpfa Avatar answered Oct 22 '22 10:10

betontalpfa


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.

like image 24
Adam Avatar answered Oct 22 '22 10:10

Adam