Gnu C / C++ compiler flags

g++ flags you want to know

  • g++ prog.cpp
    • This will compile prog.cpp to a binary named a.out in unix
  • g++ prog.cpp -o foo
    • This compiles prog.cpp to a binary name foo
  • g++ -Wall prog.cpp
    • The '-Wall' turns on all compiler warnings
  • g++ -g prog.cpp
    • The '-g' turns on debugging. This makes your code ready to run under gdb.
  • g++ -c module.cpp
    • The '-c' compiles it down to an object file, known as a '.o'. You can link together multiple object files into an executable. This is used in multiple file projects to reduce compile time.
  • g++ -O module.cpp
    • Turns on optimization, you may also specify levels (-O2).
  • g++ -E prog.cpp
    • The '-E' outputs the preproccessor output to the screen ( stdout ).
  • g++ -MM prog.cpp
    • The '-MM' outputs the Makefile dependancies for the cpp file(s) listed.
  • g++ -S prog.cpp
    • The '-S' will create a .s file that contains the gasm assembly code.