Crosscompiling

From Sharpfin
Jump to navigation Jump to search

Simple "Hello World"

Assuming you have built the Toolchain, made the changes to your environment including PATH and carried out the instructions Enabling Login, a simple "Hello World!" program is easy to build.

For the sake of this example we'll set up an alias to the crosscompiler.

  alias cc=arm-9tdmi-linux-gnu-gcc

In a working directory, create a file called helloworld.c

  #include <stdio.h>
  main() {
       printf("Hello world

");

  }

Now to build the program.

  cc -o helloworld helloworld.c

You should now have an executable program called "helloworld" of about 7000 bytes. Move this onto your radio and execute it from the command line. You should see "Hello world" and the prompt.

Please note We haven't used the radio specific library here so your text will not appear on the radio's display, just the telnet session.

At this point you've proved the crosscompiling tools are working fine.

Hint:
if you get the error 'crt*.o: No such file: No such file or directory' while compiling the hello world program, you could try to solve this problem by issuing following commands:

  # strace -f -o foo.log arm-9tdmi-linux-gnu-gcc helloworld.c

the log file will contain the information where the compiler is looking for the missing file(s). Then you can add some symbolic links if you find the file(s) elsewhere. E.g. this command could solve the problem w/ missing crt1.o:

  # for i in `ls $RESULT_TOP/build/arm-9tdmi-linux-gnu/gcc-4.1.0-glibc-2.3.2/build-glibc/csu/crt*.o`;do ln -s 
  #   $i $RESULT_TOP/build/arm-9tdmi-linux-gnu/gcc-4.1.0-glibc-2.3.2/gcc-core-prefix/lib/gcc-lib/arm-9tdmi-linux-gnu/3.3.6/${i##*/};done

but you may need to adapt it slightly

Building packages

Crosscompiling is easy these days, even with most autoconf/automake configurable packages. The following works for me

  • Create a directory where you want to put the fresh compiled libraries, header files and binaries. For example
 # mkdir -p /tmp/reciva/root
  • Make sure the toolchains 'bin' dir is in your path (as described in Toolchain)
  • Configure the package, using the cross compiler and optional previously installed libraries and headers
 # export LDFLAGS="-L/tmp/reciva/root/lib" 
 # export CPPFLAGS="-I/tmp-reciva/root/include" 
 # ./configure --prefix=/tmp/reciva/root/ --host=arm-softfloat-linux-gnu "$@"
  • If all went well, configure should finish without problems, and you can now build and install the software
 # make
 # make install