The g++ Compiler

Here are some a few of the many options that g++ supports. Use command

  man g++
for a full list.

-c

Without this option, g++ creates an executable file. With this option, it creates an object file. If no output file name is given (by option -o), the object file name for file prog.cpp is prog.o.

-g

Write information into the machine language that allows a debugger, such as gdb, to provide better information about the program.

-O

Request optimization. The compiler improves the machine-language code to make it more efficient. This can substantially speed up the program, but it also slows down compilation.

During optimization the compiler performs dataflow analysis, in which it examines how information flows in a function definition. That allows it to detect whether a variable is used before it is initialized. So requesting optimization can lead to more useful warnings.


For example, command

  g++ -Wall -W -g -o prog prog.cpp
creates executable file prog from C++ file prog.cpp, with common warnings turned on and with debugger information written into it. Command
  g++ -Wall -W -g -c prog.cpp
creates object file prog.o, ready to be linked to other object files. You cannot run prog.o by itself.