1

Compiling a simple test.c:

#include <stdio.h>

void main() {
  printf("Hello World!\n");
  while(1);
}

using CodeSourcery's arm-none-eabi-gcc I got the following errors:

arm-none-eabi-gcc -static test.c -o mytest

/opt/Sourcery_CodeBench_Lite_for_ARM_EABI/bin/../lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/bin/ld: warning: cannot find entry symbol _start; defaulting to 00008018
/opt/Sourcery_CodeBench_Lite_for_ARM_EABI/bin/../lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/lib/libc.a(lib_a-sbrkr.o): In function `_sbrk_r':
sbrkr.c:(.text+0x18): undefined reference to `_sbrk'
/opt/Sourcery_CodeBench_Lite_for_ARM_EABI/bin/../lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/lib/libc.a(lib_a-writer.o): In function `_write_r':
writer.c:(.text+0x20): undefined reference to `_write'
/opt/Sourcery_CodeBench_Lite_for_ARM_EABI/bin/../lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/lib/libc.a(lib_a-closer.o): In function `_close_r':
closer.c:(.text+0x18): undefined reference to `_close'
/opt/Sourcery_CodeBench_Lite_for_ARM_EABI/bin/../lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/lib/libc.a(lib_a-fstatr.o): In function `_fstat_r':
fstatr.c:(.text+0x1c): undefined reference to `_fstat'
/opt/Sourcery_CodeBench_Lite_for_ARM_EABI/bin/../lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/lib/libc.a(lib_a-isattyr.o): In function `_isatty_r':
isattyr.c:(.text+0x18): undefined reference to `_isatty'
/opt/Sourcery_CodeBench_Lite_for_ARM_EABI/bin/../lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/lib/libc.a(lib_a-lseekr.o): In function `_lseek_r':
lseekr.c:(.text+0x20): undefined reference to `_lseek'
/opt/Sourcery_CodeBench_Lite_for_ARM_EABI/bin/../lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/lib/libc.a(lib_a-readr.o): In function `_read_r':
readr.c:(.text+0x20): undefined reference to `_read'
collect2: error: ld returned 1 exit status

But if i used my Ubuntu (12.04 LTS 32-bit) 's arm gcc:

arm-linux-gnueabi-gcc -static -o mytest test.c

arm-linux-gnueabi-gcc -v
Using built-in specs.
COLLECT_GCC=arm-linux-gnueabi-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabi/4.6/lto-wrapper
Target: arm-linux-gnueabi
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/arm-linux-gnueabi/include/c++/4.6.3 --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --enable-multilib --disable-sjlj-exceptions --with-arch=armv7-a --with-float=softfp --with-fpu=vfpv3-d16 --with-mode=thumb --disable-werror --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=arm-linux-gnueabi --program-prefix=arm-linux-gnueabi- --includedir=/usr/arm-linux-gnueabi/include --with-headers=/usr/arm-linux-gnueabi/include --with-libs=/usr/arm-linux-gnueabi/lib
Thread model: posix
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) 

I have no error generating the output file.

can someone explain?

My best nearest reference (but still I have no success):

Linker error on a C project using eclipse

Community
  • 1
  • 1
Peter Teoh
  • 6,337
  • 4
  • 42
  • 58
  • i think i saw this link: http://balau82.wordpress.com/2010/02/28/hello-world-for-bare-metal-arm-using-qemu/ which implements lots of low level stuff in full. – Peter Teoh May 18 '14 at 04:26

1 Answers1

3

arm-none-eabi-gcc is a compiler for bare metal arm. I.e. for running on an arm processor where you have no operating system, or where you make your own operating system. That compiler contains the newlib C library, which will provide you with most of a standard C library, but you will have to provide the low level implementations (e.g. somewhere for printf() to actually print, memory management, a file system if you need it). In short, you're much on your own having to bootstrap the processor, C runtime and load the produced code (See e.g. this question))

arm-linux-gnueabi-gcc is a compiler for targeting linux running on arm, a toolchain that'll produce executables running on linux, using the familiar glibc C library and header files.

Community
  • 1
  • 1
nos
  • 223,662
  • 58
  • 417
  • 506
  • oh yes, that explained part two of question. but i am still not able to compile successfully for the simple VersatilePB QEMU arm emulator binary. What options should I put it? – Peter Teoh May 18 '14 at 03:42
  • @PeterTech I'm not entireley sure what you mean, if you mean why your 1. option does not link, it's because you need to implement quite a lot of low level functionality since you are compiling for a target that does not run any operating system. So, you need to sit down and write the implementation for many low level functions based on the datasheet for the arm processor you have (or are emulating). (http://www.emb4fun.com/arm/examples/download/syscalls.c is a minimal example, but if you want to have text appear, you need to write a display driver, or an UART driver) – nos May 18 '14 at 08:43
  • great! thanks for the answer, now I have a better understanding :-). – Peter Teoh May 18 '14 at 14:22