Re: [arm-gnu] 2007q3 link error: undefined reference to '_sbrk' etc.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [arm-gnu] 2007q3 link error: undefined reference to '_sbrk' etc.



Zhonghua wrote:
arm-2007q3/arm-none-eabi/lib/libc.a(lib_a-sbrkr.o): In function `_sbrk_r':
sbrkr.c:(.text+0x18): undefined reference to `_sbrk'
arm-2007q3/arm-none-eabi/lib/libc.a(lib_a-sysgetpid.o): In function `getpid':
sysgetpid.c:(.text+0x4): undefined reference to `_getpid'
arm-2007q3/arm-none-eabi/lib/libc.a(lib_a-times.o): In function `_times_r':
times.c:(.text+0x8): undefined reference to `_times'
arm-2007q3/arm-none-eabi/lib/libc.a(lib_a-writer.o): In function `_write_r':
writer.c:(.text+0x20): undefined reference to `_write'
arm-2007q3/arm-none-eabi/lib/libc.a(lib_a-closer.o): In function `_close_r':
closer.c:(.text+0x18): undefined reference to `_close'
arm-2007q3/arm-none-eabi/lib/libc.a(lib_a-lseekr.o): In function `_lseek_r':
lseekr.c:(.text+0x20): undefined reference to `_lseek'
arm-2007q3/arm-none-eabi/lib/libc.a(lib_a-readr.o): In function `_read_r':
readr.c:(.text+0x20): undefined reference to `_read'
arm-2007q3/arm-none-eabi/lib/libc.a(lib_a-makebuf.o): In function `__smakebuf':
makebuf.c:(.text+0xf8): undefined reference to `isatty'
arm-2007q3/arm-none-eabi/lib/libc.a(lib_a-fstatr.o): In function `_fstat_r':
fstatr.c:(.text+0x1c): undefined reference to `_fstat'
collect2: ld returned 1 exit status

I have already refered to the https://support.codesourcery.com/GNUToolchain/kbentry57. I have created a new link script: % arm-none-eabi-ld --verbose > def.lnk and remove the SERACH_DIR.
After this, I compiled a file:
% arm-none-eabi-gcc -T def.lnk -o hello hello.c
but the same error happen.

What I should do? Could you tell me.

You have three options (1) Use the unhosted library which has default "do nothing" implementations of the low-level IO. (2) Use semi-hosting and allow the low-level IO routines to be processed by the debugger. (3) Write the low-level IO routines for your board. The low-level IO routines are specific to each board.

You probably want option (1); link with "-T generic.ld"

Option (2) can be accomplished by compiling with "-T <board>-hosted.ld" where "<board>-hosted.ld" is on of the linker scripts in "arm-none-eabi/lib/*" that has semi-hosting support e.g. "-T generic-hosted.ld"

Option (3) requires that you write your own version of each of the undefined functions listed in your link e.g. _sbrk, _getpid, _time, _write, _close, _seek, _read, isatty, and _fstat. You will need to learn what each of these functions does and provide a sensible default.

Cheers,
Carlos.
--
Carlos O'Donell
CodeSourcery
carlos@xxxxxxxxxxxxxxxx
(650) 331-3385 x716