# Setting Compiler Options

You can customize the the way the compiler will compile your file or project. Remember, each project will have its own set of compiler settings. If the options are modified when there is no project open, the settings are saved separately and will be used when compiling and building single files only. These are all transparent to the user: Anjuta handles them automatically.

## Support for your program

You have have seen in the previous sections how to specify basic compile options (such as include and library paths, linker settings, and so on). This process can be cumbersome when you want to use some of the more standard or popular libraries — GTK and GNOME, for example. To enable easy implementation of these libraries and to avoid and inconsistencies, the developers of such libraries usually supply a configuration program (usually called *-config) along with their libraries.

Well, that's the theory. Now for the practical part. Anjuta will do the difficult parts for you, so you do not need to worry about the configuration programs for these libraries — just add the particular support to your project.

To add support for a library to your program:

1. Choose the menu item Settings Compiler and Linker Settings … and click on the Supports tab in the Compiler Options dialog.

2. Select the supports for your program by double-clicking on them.

3. Double-clicking again on any selected supports will unselect them.

### Supports dialog

Supports dialog

This will automatically set all the include paths and the libraries necessary for the options chosen. There will be no need to set the include paths and libraries manually.

### Available supports

Currently, Anjuta has only a few library support options — Glib, GTK, GNOME and Bonobo. Some of these are not yet fully supported.

### Compiler options for supports

Once basic library supports have been specified, there is no need to manually set the basic compiler options usually required for these libraries. Any other libraries may still need compiler settings to be changed.

## Include Paths

To set include paths for your program:

1. Choose the menu item Settings Compiler and Linker Settings … and click on the Include Paths tab in the Compiler Options dialog.

2. Enter each of the paths one by one and click on the Add button for each entry.

3. To remove an entry, select the entry in the list and click on Remove.

4. To edit an entry, select the entry, modify it in the text box and click on Update

5. To clear all of the entries, click on Clear.

### Include Paths dialog

Include Paths dialog

### Absolute or Relative include paths?

If the settings are for a project, then all include paths should be relative to the source directory of the project. Avoid using absolute paths — otherwise, when you distribute the source code, other people will have problems trying to build the program.

If the settings are are made outside of a project, then it doesn't matter whether the paths are absolute or relative — the settings will be local to your machine only.

## Library Paths

When your program links to external libraries (specified via the Libraries settings in the next section), the linker will search for those libraries in the library search paths. Anjuta will automatically use system library paths, but you should add any additional search paths to your project.

To set library paths for your program:

1. Choose the menu item Settings Compiler and Linker Settings … and click on the Library Paths tab in the Compiler Options dialog.

2. Enter each of the paths one by one and click on the Add button for each entry.

3. To remove an entry, select the entry in the list and click on Remove.

4. To edit an entry, select the entry, modify it in the text box and click on Update

5. To clear all of the entries, click on Clear.

### Library Paths dialog

Library Paths dialog

### Absolute or Relative include paths?

If the settings are for a project, then all library paths should be relative to the source directory of the project. Avoid using absolute paths — otherwise, when you distribute the source code, other people will have problems trying to build the program.

If the settings are are made outside of a project, then it doesn't matter whether the paths are absolute or relative — the settings will be local to your machine only.

## Libraries to link

Libraries are external modules that must be linked with your program at the final stage of the build, to produce another library or an executable. The linker is passed the list of libraries to link with to construct the final target.

It is also possible to provide the names of object modules (`*.o` files) along with the libraries to link against. Object modules are specified by a special flag (asterisk *) at the start of the object module name (so that Anjuta can differentiate them from the library modules). Object modules must be listed with their full paths (absolute or relative, depending upon the context), because they will not be searched for on the library search path.

Example: in the screenshot below, the first entry "scintilla" is a library, while those starting with "*" are object modules.

### Libraries dialog

Libraries dialog

Libraries follow the naming format: `libXXX.a`. When specifying libraries in the list, the prefix "lib" and the suffix ".a" are skipped, and only the library name "XXX" is given in the entry.

To set libraries for your program:

1. Choose the menu item Settings Compiler and Linker Settings … and click on the Libraries tab in the Compiler Options dialog.

2. Enter each of the library names (and object names, if required) and click on the Add button for each entry.

   Libraries can also be selected from the list shown in the right pane of the dialog. Not all libraries will be available in this list.

   ### Object module paths

   Object modules must be specified with an explicit path and must start with an asterisk (*). Explicit path means the path should be relative path of the object from the source dir and the filename should be complete (eg. ../../lib/diagram.o).

3. To remove an entry, select the entry in the list and click on Remove.

4. To disable an entry, double-click on the entry in the list. To re-enable it, double-click again.

   Entries that are disabled are not included in the the linking process.

5. To edit an entry, select the entry, modify it in the text box and click on Update

6. To clear all of the entries, click on Clear.

## Defining Macros

To define macros for your program:

1. Choose the menu item Settings Compiler and Linker Settings … and click on the Defines tab in the Compiler Options dialog.

2. Enter each macro to define one by one and click on the Add button for each entry.

3. To remove an entry, select the entry in the list and click on Remove.

4. To edit an entry, select the entry, modify it in the text box and click on Update

5. To clear all of the entries, click on Clear.

### Defines dialog

Defines dialog

## Compiler Warnings

It is possible to tell the compiler how to respond to each different type of warning.

1. Choose the menu item Settings Compiler and Linker Settings … and click on the Warnings tab in the Compiler Options dialog.

2. Select the warnings you want to see in the Message window when you compile or build your file or project.

3. Selecting No Warnings will disable all warnings.

4. Similarly, selecting All Warnings will enable all warnings.

### Warnings dialog

Warnings dialog

## Code Optimization

To set the level of Optimization for code compilation:

1. Choose the menu item Settings Compiler and Linker Settings … and click on the Optimization tab in the Compiler Options dialog.

2. Select the level of optimization required.

### Optimization dialog

Optimization dialog

Note that it is not a good idea to enable any sort of optimization if you have also enabled debugging. It will not do any harm to do so, but it will make life much more difficult when debugging the program. With optimization enabled, the compiler will modify your code to improve performance. This sometimes creates confusion during debugging, as the line number that the debugger refers to will not always correspond to the actual line number in the source file.

Code optimization takes place during the compilation stage only, and does not affect the source code in the file.

## Other compiler settings

To set miscellaneous compiler settings:

1. Choose the menu item Settings Compiler and Linker Settings … and click on the Others tab in the Compiler Options dialog.

2. Various options for compiling are set on this tabbed section.

### Other Compiler Settings dialog

Other Compiler Settings dialog

The first is the Enable Debugging option. This option tells the compiler to add extra debug information (such as the symbol table), which is necessary for stepping through the code. This makes the program slightly larger.

This option will be most useful during the development of your program. When the code is ready for the release, disable this option and build the program again. The project should be cleaned first before the rebuild — otherwise, due to automatic dependency checking, not all of the files may be built with this option disabled.

Note that it is not a good idea to enable any sort of optimization if you have also enabled debugging. It will not do any harm to do so, but it will make life much more difficult when debugging the program. With optimization enabled, the compiler will modify your code to improve performance. This sometimes creates confusion during debugging, as the line number that the debugger refers to will not always correspond to the actual line number in the source file.

The second option Enable Profiling is similar to the Enable Debugging option, except that it builds your program with profiling information. Profiling is not yet implemented in Anjuta. For the time being, you can use gprof, a console-based profiler; or MemProf, which is a GUI (GTK) application. Read the gprof manual page to learn how to profile your program. Enabling profiling will make a progam run very slowly, so it should only be used for debugging.

Additional options to pass to the compiler and linker can be entered into the text boxes on this tabbed section.