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 standard Axis SDK environment using C++

Install the Axis SDK on your Linux box and go to the devboard-R_01 directory and type:
# . init_env
# cd apps
# mkdir helloworld
# cd helloworld
Edit this source code and save it with the name helloworld.cpp
WARNING!! File extention MUST BE "cpp".

#include "iostream"

using namespace std;

int main(void) 
  cout << "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
INSTDIR   = $(prefix)/mnt/flash/
INSTMODE  = 0755
OBJS      = helloworld.o
OPTIONS   = -static

all: $(PROGS)

  $(CXX) $(OPTIONS) $(LDFLAGS) $^ $(LDLIBS) -o $@

install: $(PROGS)
  rm -f $(PROGS) *.o core

WARNING!! You MUST use TAB and don't use SPACE at the begin of follow rows:

$(CXX) $(LDFLAGS) $^ $(LDLIBS) -o $@
rm -f $(PROGS) *.o core

Using SPACE, produce follow error when run make:

Makefile.xx:*** missing separator. Stop
Now let's to try our program in the host operating sistem, type:
# make host
make[1]: Entering directory `/home/devboard-R2_01/apps/helloworld'
make[1]: Leaving directory `/home/devboard-R2_01/apps/helloworld'

Then type:

# make
g++ -Wall -Wshadow -I/root/fox/devboard-R2_01/target/host/include -O0 -g
-fno-omit-frame-pointer -Wno-ctor-dtor-privacy -ansi -pipe -c -o helloworld.o helloworld.cpp
g++ -static -L/root/fox/devboard-R2_01/target/host/lib
-Wl,-rpath-link,/root/fox/devboard-R2_01/target/host/lib helloworld.o -o helloworld

And now run the program.

Hello World!
Now select like target the Fox board. Type:
# make cris-axis-linux-gnu
make[1]: Entering directory `/root/fox/devboard-R2_01/apps/HelloWorld'
rm -f helloworld *.o core
cp "/root/fox/devboard-R2_01/apps/HelloWorld/" .target-makefrag
make[1]: Leaving directory `/root/fox/devboard-R2_01/apps/HelloWorld'
Then make the executable. Type:
# make
g++-cris -isystem /root/fox/devboard-R2_01/target/cris-axis-linux-gnu/include -mlinux
-mno-mul-bug-workaround -Wall -Wshadow -O2 -g -Wno-ctor-dtor-privacy -ansi -pipe -c -o helloworld.o helloworld.cpp
g++-cris -isystem /root/fox/devboard-R2_01/target/cris-axis-linux-gnu/include -mlinux
-mno-mul-bug-workaround -static -L/root/fox/devboard-R2_01/target/cris-axis-linux-gnu/lib
-Wl,-rpath-link,/root/fox/devboard-R2_01/target/cris-axis-linux-gnu/lib helloworld.o -o helloworld

The excutable size after compiling is 5673064 byte, to verify it, type:

# ls -al hellowolrd
-rwxr-xr-x   1 root root 5673064 25 mag 09:47   helloworld
WARNING!!! The size is too bit to copy on the on board flash.
To run "helloworld"you MUST connect a Pen Drive to USB port, mount and copy helloworld on It.

Using telnet (TELNET access) run the program.

Reduce executable size to fit on the on board flash

It's possible to reduce executable size running follow command. Type:
# cris-strip --strip-unneeded helloworld
The reduced size is 556000 byte, and now we can copy helloworld to the on board Fox flash.
# ls -al hellowolrd
-rwxr-xr-x   1 root root 556000 25 mag 09:47   helloworld


Many thank to Pierluigi Bucolo for this article