Crosscompiling: Difference between revisions

From Sharpfin
Jump to navigation Jump to search
(Added simple "Hello World" example.)
No edit summary

Revision as of 11:27, 5 December 2011

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.


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 /tmp/reciva/root
  • Make sure the toolchains 'bin' dir is in your path
 # export PATH=$PATH:/opt/crosstool/gcc-3.3.4-glibc-2.3.2/arm-softfloat-linux-gnu/bin/
  • 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