100 Useful Command-Line Utilities

by Oliver; 2014

80. g++

Compile a C++ program, myprogram.cpp:
$ g++ myprogram.cpp -o myprogram
This produces the executable myprogram. Stackoverflow has a nice post about the g++ optimization flags, which includes the bit:
The rule of thumb:
When you need to debug, use -O0 (and -g to generate debugging symbols.)
When you are preparing to ship it, use -O2.
When you use gentoo, use -O3...!
When you need to put it on an embedded system, use -Os (optimize for size, not for efficiency.)
I usually use -O2:
$ g++ -O2 myprogram.cpp -o myprogram
Read about GCC, the GNU Compiler Collection, here.

<PREV   NEXT>