eclipes CDT : Creating a simple Standard C++ Project -- "Hello World on a Windows Platform"

来源:互联网 发布:python 遗传算法库 编辑:程序博客网 时间:2024/05/17 03:37
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:

  1. In the C/C++ Projects View right click and select "New Project ..."
  2. Select "C++" in the left pane and the select "Standard Make C++ Project"
  3. 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.
  4. In the C/C++ Projects View right click and select "New" > "Simple" > "File". Name your file hello.cpp
  5. Repeat the previous step and name the second new file "makefile".
  6. 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.

  7. 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.