Using standard libraries in gcc environment

17 Aug 2011

Hello

I've tried to compile some code on an offline compiler because I've done an application with mbed for my thesis and I'd like the code to be independent from mbed compiler.

I use GNU ARM gcc compiler on Eclipse. Everything works fine for basic code, but the problem is that my code uses some standard C library functions. If I call a basic function, like printf, the compiler offers a huge pile of errors.

Description				Location	Type
undefined reference to `_close'		line 0		C/C++ Problem
undefined reference to `_fstat'		line 0		C/C++ Problem
undefined reference to `_isatty'	line 0		C/C++ Problem
undefined reference to `_lseek'		line 0		C/C++ Problem
undefined reference to `_read'		line 0		C/C++ Problem
undefined reference to `_sbrk'		line 0		C/C++ Problem
undefined reference to `_write'		line 0		C/C++ Problem

I'm suspecting there is something wrong with the linker file since these libraries must work on LPC1768 - Afterall, these standard functions work in mbed online compiler!

I'm a complete newbie on ARM and gcc so any advice is welcome.

17 Aug 2011

maybe the problem is, that you use c++. so you have to do

extern "C"{
...
}

around you headers that implement c-functions

18 Aug 2011

Research revealed that those functions are missing standard functions included in operating systems as default. Since mbed does not have any kind of OS, it is missing those functions the standard libraries are trying to reach. This causes the compiler errors.

I managed to find stubs written for those functions for mbed NXP 1768. Now the code compiles, but the system freezes when it calls a standard function.

This reinforces my belief that the closer you move from embedded low-level code towards PC-like programming the more you have to waste time on configuring and being highly unproductive. Hoho.

18 Aug 2011

maybe this http://mbed.org/users/yumyumbird/notebook/basic-offline-compiling-library/ could help you. couldn't find the original posting, it is not my work.

18 Aug 2011

Juho Lepisto wrote:

This reinforces my belief that the closer you move from embedded low-level code towards PC-like programming the more you have to waste time on configuring and being highly unproductive. Hoho.

Agreed :-) But when you got your toolchain ready and your basic functions, then you can be very productive in producing highly complicated, hard to read code.

18 Aug 2011

Well, almost all "foreign" (code that someone else has written) is hard to read. Hoho. But yeah, pile of register manipulations can get a bit cryptic, especially if commenting is neglected or otherwise bad. On the upside, at least you know exactly what's happening.

I managed to find a solution for my problem from this thread: http://mbed.org/forum/mbed/topic/2336/ It still uses some m.bed library functionality, but at least it compiles offline smoothly. Although the size is insane: 136 KB offline vs. 39 KB online.

18 Aug 2011

yes I know, the ARM EABI GNU - compiler is not that optimizing than the Keil - compiler. but I never had problems with that,even bith big projects. the mbed has got great capabilities.