Next: , Up: Introduction to GPS


1.5.1 Building a New Program with GPS

GPS invokes the GNAT compilation tools using information contained in a project (also known as a project file): a collection of properties such as source directories, identities of main subprograms, tool switches, etc., and their associated values. (See GNAT Project Manager, for details.) In order to run GPS, you will need to either create a new project or else open an existing one.

This section will explain how you can use GPS to create a project, to associate Ada source files with a project, and to build and run programs.

  1. Creating a project

    Invoke GPS, either from the command line or the platform's IDE. After it starts, GPS will display a “Welcome” screen with three radio buttons:

    Select Create new project with wizard and press OK. A new window will appear. In the text box labeled with Enter the name of the project to create, type sample as the project name. In the next box, browse to choose the directory in which you would like to create the project file. After selecting an appropriate directory, press Forward.

    A window will appear with the title Version Control System Configuration. Simply press Forward.

    A window will appear with the title Please select the source directories for this project. The directory that you specified for the project file will be selected by default as the one to use for sources; simply press Forward.

    A window will appear with the title Please select the build directory for this project. The directory that you specified for the project file will be selected by default for object files and executables; simply press Forward.

    A window will appear with the title Please select the main units for this project. You will supply this information later, after creating the source file. Simply press Forward for now.

    A window will appear with the title Please select the switches to build the project. Press Apply. This will create a project file named sample.prj in the directory that you had specified.

  2. Creating and saving the source file

    After you create the new project, a GPS window will appear, which is partitioned into two main sections:

    Select File on the menu bar, and then the New command. The Workspace area will become white, and you can now enter the source program explicitly. Type the following text

              with Ada.Text_IO; use Ada.Text_IO;
              procedure Hello is
              begin
                Put_Line("Hello from GPS!");
              end Hello;
         

    Select File, then Save As, and enter the source file name hello.adb. The file will be saved in the same directory you specified as the location of the default project file.

  3. Updating the project file

    You need to add the new source file to the project. To do this, select the Project menu and then Edit project properties. Click the Main files tab on the left, and then the Add button. Choose hello.adb from the list, and press Open. The project settings window will reflect this action. Click OK.

  4. Building and running the program

    In the main GPS window, now choose the Build menu, then Make, and select hello.adb. The Messages window will display the resulting invocations of gcc, gnatbind, and gnatlink (reflecting the default switch settings from the project file that you created) and then a “successful compilation/build” message.

    To run the program, choose the Build menu, then Run, and select hello. An Arguments Selection window will appear. There are no command line arguments, so just click OK.

    The Messages window will now display the program's output (the string Hello from GPS), and at the bottom of the GPS window a status update is displayed (Run: hello). Close the GPS window (or select File, then Exit) to terminate this GPS session.