next up previous contents
Next: Example: Compiling Zoo Classes Up: Compiling Previous: Preprocessing   Contents

Compiler Options

Some of the more important compiler options a beginner should know about are:-

-c
Stops processing after compilation is complete. The g++ command is in fact a driver that can run both the compiler and linker and for trivial programs its convenient to compile and link in a single step. However for projects of any significant size, its normal to keep the two steps separate.

-g
This instructs the compiler to generate additional information to help when debugging. See section 6.1.6.

-Dmacro
Define the preprocessor macro macro. See section 6.1.2 This can be used to switch on/off blocks of code when used with the #ifdef preprocessor. For example you could have extra printout that's not normally executed by using for example a VERBOSE macro:-

  #ifdef VERBOSE
  //   verbose code goes here
  ...
  #endif

By default, such code is disabled but could be switched on with:-

g++ -DVERBOSE ...

The option can be used any number of times to define macros as required.

-Idirectory
This tell the compiler to look in the directory directory for #include files, see section 6.1.2. The option can be used any number of times to define additional directories to be searched e.g.:-

g++ -I/home/software/include -IMyCode/include ...


next up previous contents
Next: Example: Compiling Zoo Classes Up: Compiling Previous: Preprocessing   Contents
P.D. Gronbech (IT Staff) 2015-10-02