PLEASE NOTE: This article is obsolete or related to a discontinued product.

Compile a C application

This tutorial explains how to compile the classic Hello World ! example using the SDK environment

Install the SDK on your Linux box and go to the devboard-R_01 directory, then type:
/home/fox/devboard-R_01# . init_env
Prepending "/..../devboard-R2_01/tools/build/bin" to PATH.
Prepending "/usr/local/cris/bin" to PATH.
/home/fox/devboard-R_01# cd apps
Create a new directory with the same name of your application:
/home/fox/devboard-R_01/apps# mkdir helloworld
/home/fox/devboard-R_01/apps/helloworld# cd helloworld
Edit this source code and save it with the name helloworld.c:
#include "stdio.h"

int main(void) {
  printf("Hello world !\n");
  return 0;
Edit this file and save it with the name Makefile:
include $(AXIS_TOP_DIR)/tools/build/Rules.axis

PROGS = helloworld

all: $(PROGS)
$(PROGS): $(PROGS).o
	$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@

	rm -f $(PROGS) *.o core

If your program have to run on a FOX with glibc library (delivered by default with the FOX with Kernel 2.4.x and the present svn based SDK) type:

/home/fox/devboard-R_01/apps/helloworld# make cris-axis-linux-gnu
make[1]: Entering directory `/home/devboard-R2_01/apps/helloworld'
make[1]: Leaving directory `/home/devboard-R2_01/apps/helloworld'
If your program have to run on a FOX with uClibc library type (delivered by default with some FOXes with Kernel 2.6.x or if you chose uclibc as main "C" library in the "make menuconfig" SDK parameter selection phase) type:
/home/fox/devboard-R_01/apps/helloworld# make cris-axis-linux-gnuuclibc
make[1]: Entering directory `/home/devboard-R2_01/apps/helloworld'
make[1]: Leaving directory `/home/devboard-R2_01/apps/helloworld'
Inside the directory helloworld will be created a hidden file .target-makefrag that has instructions for the make process on which general library and environment to consider during the compilation phase.

Now type:

/home/fox/devboard-R_01/apps/helloworld# make
 gcc-cris  -isystem /home/devboard-R2_01/target/cris-axis-linux-gnu/include 
   -mlinux -mno-mul-bug-workaround -Wall -Wshadow -O2 -g    -c -o helloworld.o helloworld.c
 gcc-cris  -isystem /home/devboard-R2_01/target/cris-axis-linux-gnu/include 
   -mlinux -mno-mul-bug-workaround  -L/home/devboard-R2_01/target/cris-axis-linux-gnu/lib 
   -Wl,-rpath-link,/home/devboard-R2_01/target/cris-axis-linux-gnu/lib helloworld.o  -o helloworld
If everythings goes well you'll have the executable file helloworld ready to run on your FOX board:
/home/fox/devboard-R_01/apps/helloworld# ls -l
 total 40
 -rwxr-xr-x  1 root root 17684 Oct 26 17:45 helloworld
 -rw-r--r--  1 root root    80 Mar  3  2005 helloworld.c
 -rw-r--r--  1 root root 11868 Oct 26 17:45 helloworld.o
 -rw-r--r--  1 root root   478 Oct 26 16:54 Makefile
Now to run this program you have to transfer it on the FOX Board. The easiest way is to use SCP:
/home/fox/devboard-R_01/apps/helloworld# scp helloworld root@
The authenticity of host ' (' can't be established.
RSA key fingerprint is 89:2f:6e:f7:5b:d0:02:07:d3:9d:18:10:76:6e:99:0c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '' (RSA) to the list of known hosts.
root@'s password: pass
Now open another terminal session and launch Telnet:
# telnet
Entering character mode
Escape character is '^]'.

axis-00408c012220 login: root
Password: pass
go to the directory /mnt/flash
[root@axis-00408c012220 /root]182# cd /mnt/flash
[root@axis-00408c012220 /mnt/flash]182#

In order to set this file as an executable you have to issue the following command (to be issued only one time i.e. modifying the program and updating it on the Fox will retain its status as executable program):

[root@axis-00408c012220 /mnt/flash]182# chmod +x helloworld
Now you can launch your first helloworld program on the FOX Board:
[root@axis-00408c012220 /mnt/flash] # ./helloworld
Hello world !

Related links