Difference between revisions of "HelloWorldCpp"
(Creation) |
m (→Compilation) |
||
Line 36: | Line 36: | ||
So to compile your small program do (here hello.cpp was saved in armadeus/target/demos/ directory): | So to compile your small program do (here hello.cpp was saved in armadeus/target/demos/ directory): | ||
− | [host demos]$ ../../buildroot/build_arm_nofpu/staging_dir/bin/arm-linux-g++ -o hello hello. | + | [host demos]$ ../../buildroot/build_arm_nofpu/staging_dir/bin/arm-linux-g++ -o hello hello.cpp |
==Running== | ==Running== |
Revision as of 21:23, 3 April 2007
On this page you will learn how to create your first C++ application for your Armadeus board
Contents
Source code
First take your favorite editor/IDE and create the following program:
#include <iostream> using namespace std; class Hello { private: const char* message; public: Hello( const char* amessage ) { message = amessage; }; virtual ~Hello() { cout << "Bye, bye !" << endl; }; void speaks { cout << message << endl; }; }; int main() { Hello hello( "APF9328 says Hello everybody !" ); hello.speaks(); return 0; }
Save it as hello.cpp
Compilation
The C++ cross compiler is installed in armadeus/buildroot/build_arm_nofpu/staging_dir/bin/ and is named arm-linux-g++ There are 2 possibilities to use it:
- either add armadeus/buildroot/build_arm_nofpu/staging_dir/bin/ to your PATH environment variable and then call arm-linux-g++ instead of g++
- or call directly armadeus/buildroot/build_arm_nofpu/staging_dir/bin/arm-linux-g++
So to compile your small program do (here hello.cpp was saved in armadeus/target/demos/ directory):
[host demos]$ ../../buildroot/build_arm_nofpu/staging_dir/bin/arm-linux-g++ -o hello hello.cpp
Running
Copy your hello executable on your board either through TFTP or NFS
TFTP
Be sure to have TFTP server installed, if not it's explained here
Copy hello to TFTP directory:
[host demos]$ cp hello /tftpboot/
Load your executable on the target (here my host IP is 192.168.0.2):
# tftp -g -r hello -l /usr/bin/hello 192.168.0.2
Give it executable rights, if lost during TFTP transfer:
# chmod a+x /usr/bin/hello
Launch it:
# /usr/bin/hello APF9328 says: Hello World ! ;-) #
Now it's up to you ! ;-)
NFS
Be sure to have NFS server installed, if not it's explained here
I assume that your NFS drive is accessible from /mnt/host
Launch your prog:
[target]# /mnt/host/hello
Putting it all together in a Makefile
You can put your program compiling and copying in a Makefile to make things cleaner:
CXX=arm-linux-g++ CXXFLAGS=-W -Wall LDFLAGS= EXEC=hello SRC= $(wildcard *.cpp) OBJ= $(SRC:.c=.o) all: $(EXEC) hello: $(OBJ) $(CXX) -o $@ $^ $(LDFLAGS) %.o: %.c $(CXX) -o $@ -c $< $(CXXFLAGS) .PHONY: clean install clean: rm -rf *.o install: cp -f $(EXEC) /tftpboot/
!! If you do a cut & paste with previous commands, don't forget to check TABS for each target (Makefiles are using TABS and not SPACES) !!
Then, just do:
[host demos]$ make