Tutorial: Creating a simple application

In this tutorial, you will use the CDT to create a simple 'Hello World' application. This tutorial describes the process of creating a new C++ project where the build is automatically managed by the CDT.

Note: In earlier versions of the CDT, there were two separate project types: Managed make (automatically generated a makefile) and Standard make (required the user's makefile to build). With CDT 4.0, you now select a project type, and that determines what build system will be used.

To create a simple "Hello World" application using the CDT, you will perform the following steps:

Step 1: Creating a project

  1. Select File > New > Project.


    Click here to see an illustration (displayed in a separate window).


  2. Select the type of project to create. For this tutorial, expand the C++ folder and select C++ Project.


    The C++ Project wizard opens. Click here to see an illustration.


    By default, the CDT filters the Toolchain and Project types that currently display in those lists are based on the language support for the C++ Project wizard you selected for this tutorial.

  3. In the Project name field, type a name for the project.
  4. From the Project types list, expand Executable and select Hello World C++ Example. This project type provides a simple Hello World application in C++, and the makefile is automatically created by the CDT.
  5. Select a required toolchain from the Toolchain list.

    A toolchain is a set of tools (such as a compiler, linker, and assembler) intended to build your project. Additional tools, such as a debugger, can be associated with a toolchain.
    There can be several toolchains available, depending on the compilers installed on your system.

  6. Optional: If you want to change these default settings, click Advanced Settings at Step 10instead of clicking Finish.

    If the C++ perspective is not currectly set as the default, you are prompted to determined if you would like to this project to be associated with the C/C++ perspective. Click Yes.
    Click here to see an illustration.


    A project is created with the default settings and a full set of configurations based on the project type and toolchain you selected.

  7. If you clicked Next at Step 7, you can specify the basic properties for the new project, such as your name, copyright, and source information.


    Click here to see an illustration.


  8. Click Next.

    The Select Configurations window displays a list of configurations based on the project type and toolchain(s) you selected earlier.
    Click here to see an illustration.


  9. Click Finish.

    You should now see the new project in C/C++ Projects view.

    If C/C++ perspective was not set as current before, it will be selected now.

    Step 2: Creating a new file for the project

    Now, you will create a new .cpp file (such as main.cpp) that will contain some code that you will copy from another file into an editor.

    1. Right-click on your project in the Navigator.
    2. Select New > Source File.

      You should now see the new project in the C/C++ Projects view under the project, and the new file opens in the Editor view.

    Step 3: Enter and step through the code

    1. Copy the code from the file main.cpp file that was just created.

      You can double click the main.cpp tab in the Editor view to expand the view.
      Note: Leave a blank line at the end of the code because it is required by some compilers.

      On the tab in the Editor view, an asterisk character ("*") prefixes the file name. The asterisk indicates that the file has changed but has not been saved.

    2. Notice that the Outline view has also been populated with objects created from your code.

      If you select an item from the Outline view, the corresponding text in the editor is highlighted.

    3. Save the main.cpp file by clicking File > Save or pressing CTRL+S.
    4. Build your project by pressing CTRL+B.

      You can read through the build messages in the Console view. The project should build successfully, showing the following message:

      Finished building target: HelloWorld.exe


      You will also see the Outline view has also been populated with objects created from your code.

      If you select an item from the Outline view, the corresponding text in the editor is highlighted.

    Step 4: Running the application

    1. To run your application within the C/C++ Perspective, click Run > Run...
    2. Select C/C++ Local Application.
    3. Click 'New'.
    4. Click 'New'.

      A new Run Configuration is created. Its name and path to executable are provided by the project ('HelloWorld' in our case).

    5. Click 'Run'.

    Step 5: Reviewing and interpreting the results in the Console view

    Now, you should now see the Hello World application running in the Console view. The Console also shows which application is running in a title bar. You can configure this view to display different elements (such as user input elements) using different colors.

    1. Type in your name and press Enter.

      The title bar in the Console view shows you when the program has terminated.

    2. You can click the other views to see the information that they contain.

    QNX Software Systems Copyright Statement