# . init_env # cd apps
# mkdir helloworld # cd helloworldEdit this source code and save it with the name helloworld.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:
AXIS_USABLE_LIBS = GLIBC include $(AXIS_TOP_DIR)/tools/build/Rules.axis PROGS = helloworld INSTDIR = $(prefix)/mnt/flash/ INSTMODE = 0755 INSTOWNER = root INSTGROUP = root OBJS = helloworld.o OPTIONS = -static all: $(PROGS) $(PROGS): $(OBJS) $(CXX) $(OPTIONS) $(LDFLAGS) $^ $(LDLIBS) -o $@ install: $(PROGS) $(INSTALL) -d $(INSTDIR) $(INSTALL) -m $(INSTMODE) -o $(INSTOWNER) -g $(INSTGROUP) $(PROGS) $(INSTDIR) clean: 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 $@ $(INSTALL) -d $(INSTDIR) $(INSTALL) -m $(INSTMODE) -o $(INSTOWNER) -g $(INSTGROUP) $(PROGS) $(INSTDIR) rm -f $(PROGS) *.o core
Using SPACE, produce follow error when run make:
Makefile.xx:*** missing separator. StopNow 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.
#./helloworld 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/.tmp.target-makefrag" .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 helloworldWARNING!!! The size is too bit to copy on the on board flash.
Using telnet (TELNET access) run the program.
# cris-strip --strip-unneeded helloworldThe 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