Creating a simple Standard C++ Project -- "Hello World on a Windows Platform"
This section will use an example to create the familiar "Hello World!" C++ program. First, ensure that you have the CDT installed within Eclipse, as described above. Open a C/C++ Perspective and complete the following steps:
- In the C/C++ Projects View right click and select "New Project ..."
- Select "C++" in the left pane and the select "Standard Make C++ Project"
- Enter a name for the new project and select Finish. Note: you can determine the "Build Settings" from this dialog, but we will do so later, in the build section.
- In the C/C++ Projects View right click and select "New" > "Simple" > "File". Name your file hello.cpp
- Repeat the previous step and name the second new file "makefile".
- Copy the following text into the "hello.cpp" file:
#include <stdio.h>
int main()
{
printf("Hello World/n");
//block until user types something
fgetc(stdin);
return 0;
}Now, save the file.
- Copy the following text into the "makefile" file:
Remember that makefile requires that indented lines use a <tab> character and not spaces
hello.exe : hello.o
g++ -o hello.exe hello.o
hello.o : hello.cpp
g++ -c hello.cpp
all : hello.exe
clean :
-rm hello.exe hello.o
Now, save the file.