Here's a crash-course in g++ flags I've given to my students in the past as a quick reference.
# Compile Flags
-c -- Just compile, don't link
-o crawdad.o -- call your output crawdad.o
-O -- optimize a little
-O1 -- optimize for space in the Icache
-O2 -- optimize a little more
-O3 -- go hog-wild on optimization
-march=opteron -- make code specifically for opteron processors (other targets out there too...)
-m64 -- generate 64-bit code
-m32 -- generate 32-bit code
-fPIC -- generate position independent code (useful for libraries)
-fcheck-new -- make sure operator new doesn't fail
-Wall -- give me every anal warning the compiler is able to produce
-Wswitch -- just warn me on nasty switches
-Wunused-label -- warn me if I use labels without a corresponding goto
-Wconversion -- warn me if I try to do some nefarious conversion
-Wunused -- warn me if I declare a variable but don't use it
-g -- Put some nominal debugging symbols in the code
-g3 -- debug level 3
-ggdb -- Put gdb's debugging symbols in the code
-Imydir -- Include mydir/ in the path to look for #included files
-D'SMACKY=7' -- Put a #define SMACKY 7 at the start of each compiled file
-DSMACKY -- #define SMACKY, but leave the definition empty
# Linker flags
-lz -- Link with zlib (dynamically)
-lm -- link with math (dynamically)
-lpthread -- link with libpthread (dynamicaly), etc.
-Llibdir -- Look in libdir/ for dynamic libraries at runtime
-pg -- Link for gprof
-Wl,-R/my/secret/path -- Ignore your usual link practices -- try link against libraries in /my/secret/path instead