Øvelse+2+-+Building+C+programs+for+host

=Exercise 1 The Hello World program= In the File hello.cpp write a small Hello World! C++ program. Use direct compiler invocation of the compiler g++ to build your program to an executable hello. Correct any errors you may have, then execute your program

For at compile et projekt kan man bruge forskellige compilere, vi har valgt at bruge en gnu compiler. For at compile et projekt: **g++ -o 'filename' 'file.cpp' -> g++ -o hello hello.cpp**
 * filename = Use filename as the name of the file produced by g++ (usually, this is an executable file). **
 * file.cpp = projekt files **

=Exercise 2 Using makefiles= Write a makefile for the program hello you created in the firrst exercise. Add a target all that compiles your program, furthermore use variables to specify the following:
 * Source files
 * Object files
 * The name of the executable
 * The used compiler.

Build your program using make and execute it. Add two targets to your makefile; "all" that makes your executable hello inclusive the necessary objects and "clean" that removes them all. Add a target "help" to the makefile that prints a list of available targets. Test the targets all and clean.



**Exercise 3 Program based on multiple files** Create a simple program parts consisting of 5 files:

contains 1 simple function part1 that prints "This is part 1!" on stdout
 * part1.cpp

contains the denition of part1 contains 1 simple function part2 that prints "This is part 2!" on stdout contains the denition of part2 contains main which calls part1 and part2 Create a makefile for parts. As in Exercise 2, specify source files, object files, executable and the used compiler by means of variables. Add targets "clean" and "help" as in Exercise 2.
 * part1.h
 * part2.cpp
 * part2.h
 * main.cpp





=Exercise 4 Using Eclipse= Use Eclipse to create a C++ project containing les as in Exercise 3. Then use Eclipse to build the program. Finally, execute it from a prompt.

NOTE: To run eclipse, open a terminal and type runeclipse.

Eclipse asks for a "workspace folder" when starting. it is pointed to ~/workspace/ex2/ex2-parts-eclipse

The cpp ciles and header files from the previous "parts" exercise are then imported into the project code cd ~/workspaces/ex2 cp *.cpp ex2-parts-eclipse cp *.h ex2-parts-eclipse cd ex2-parts-eclipse rm hello.cpp (the hello.cpp file is not used but was copied because of the cp *.cpp command) code We the select build all:

a further inspection of the project-tree in the left hand pane of the eclipse window reveals that: ECLIPSE GENERATES IT's OWN MAKEFILE! :D