# Building Programs

Source-Navigator allows you to build executable programs from the files in your project. Using Source-Navigator, you can compile your code, navigate to any errors, link your code, and, with your debugger, set up a debugging session to debug your code.

Note: | The compiler, `make`, and debugger must be installed on your machine before using these features.

At the end of this chapter, there is a build tutorial for a command line-driven real estate trading game.

## The Building Process

The building process compiles and links source files, such as libraries and executable files, to produce an output binary file.

#### Build Process

There are four steps to building your program:

- editing your code,
- compiling your source into an intermediate format, called object files,
- linking your object files together to produce an application executable file,
- debugging your executable to find any problems.

The minimum requirements for building source code include specifying which source files should be included, the directory in which the build should be stored, linking rules, debugging, and optimization flags, and included paths.

You can edit your code using Source-Navigator. This chapter explains compiling and linking. For information about external stand-alone debuggers, see either the Debugger chapter in this manual or your debugger's documentation.

## make

Source-Navigator uses a utility called `make`. `make` combines a set of rules for compiling and linking code with a tracking mechanism for determining which files must be compiled.

Source-Navigator generates a `makefile`, which `make` uses to determine which commands need to be executed in order to build your program.

## Build Targets

A build target is a conceptual object that contains information needed to compile and link a project. For example, `hello.c` is converted into `hello.o` before `hello.exe` is built. `hello.o` requires converting rules and information regarding which libraries to use to complete the conversion to `hello.exe`.

The first time you select Build Settings... , the Build Targets list is empty. After you create a target, its name appears in the list.

### Creating a New Build Target

Choose Tools -> Build Settings... to start the Build Settings dialog.

#### Build Settings Window

Enter the name of the target in the text entry box and click the Create button. The Edit Target dialog opens. See Editing a Target.

### Modifying Build Targets

Rename a build target by selecting the target, entering a new name, and clicking the Rename button.

To edit an existing build target, select the target and click the Edit button.

Duplicating a target is useful when a new target is only slightly different from an existing target. To duplicate an existing target, select the target in the Build Targets list and click the Duplicate button.

Delete a target by selecting it in the Build Targets list and clicking Delete. The target is removed from the listing.

### Editing a Target

In the Build Targets list, either select the target name and click Edit or double-click the target name. The Edit Target window opens.

#### Edit Target Window Tabs

#### Edit Target Tabs

The Build Directory, Target Type, and Tool Chain combo-boxes are common to the tabs accessed in the Edit Target dialog.

These store information about the target.

#### Build Directory

This is the directory where all files generated in the build process are initially stored. By default this is blank. To specify the directory, either type the directory path or click the "..." button. If you click the "..." button, the Browse for Folder dialog opens:

Select the directory to store the intermediate files. Click OK to close the dialog. The directory appears in the Build Directory field.

#### Target Type

Use this combo-box to select the type of target to create. The options are executable and library.

#### Tool Chain

A tool chain is a set of compilers, debuggers, and linkers. The default for Tool Chain is GNUPro (native).

#### Source Files Tab

The Source Files tab controls which source files are included in your target. The Project Files and Target Files sections contain tree information for the selected target.

#### Importing Files and Directories

To import files or directories into your currently active project, follow these steps:

1. Under Import, click either the Files or Directory button.
2. Click the files or directory you wish to add to the project. Click OK when done. The names of the added files or directory appear in the Project Files list.

#### Adding Files

Add files to the Target Files list by selecting them from the Project Files list and clicking the Add Files button. The files are copied into the Target Files list.

#### Removing Files

You can remove files from the Target Files section by selecting them and clicking the Clear button. To remove all of the files from the Target Files section, click the Clear All button.

#### Library Files Tab

Most libraries required for building targets are linked in automatically by the compiler/linker. If you know that your target requires additional libraries, use the Library Files tab to add them to your build.

#### Library Files Tab of the Build Targets Menu

Add additional libraries by clicking the Add... button. The Open dialog opens to the last directory you have looked at in this project. After you select a library and click Open, it appears in the library list.

To remove a library from the listing, select the library and click the Remove button. The library is removed from the build.

Libraries are linked in the order listed in the window. To change the order of libraries, select the library and click either the Move Up or Move Down button to change its linking order.

#### Build Rules Tab

Click the Build Rules tab to configure each rule in the target.

A rule contains information required to compile files in a project. For example, a rule to compile a C file might contain information about which compiler and flags to use, as well as what the file is called after it's compiled.

This tab lists the rules for the specified target. Within the Build Rules tab, you can:

- disable and enable rules for the target.
- edit existing rules.

#### Build Rules Tab

Note: | The Command Line for Selected Rule displays the command line for the selected rule.

#### Status

This column shows the currently enabled and disabled rules. To disable a rule, highlight the rule and click the Disable button. To enable a rule, highlight the rule and click the Enable button.

Note: | This button changes between Disable and Enable depending upon the state of the rule.

#### File Type

This column displays the type of file the rule acts upon.

#### Description

This column displays a description of the rule.

#### Editing a Rule

To edit a rule, select the rule from the rule listing. Click the Edit Rule button. The Build Rule Settings dialog window opens. The dialog title bar displays the extension for the files involved.

#### Settings Tab

The Settings tab allows you to change the default settings for the rule.

#### Build Rule Settings with Options Selected

Debug:
This controls the debug information generated by the compiler.

Warnings:
Controls the level of warnings the compiler generates. A stricter warning ensures fewer problems with future compatibility. Set "Warnings as Errors" to make sure the compile stops any time a warning is generated.

User Flags:
Enter flags not covered by the options listed in this screen. To add macros, see the Defines Tab.

Optimization:
Compiler optimization for the code.