GCC tutorials

stevf

Senior member
Jan 26, 2005
290
0
0
Anyone know a good GCC tutorial or two? Looking to expand beyond visual studio for C and C++ and so far the tutorials I have found are far too simple, not much more than use g++ -Wall file.cpp -o filename it seems. at the other extreme are the man pages and GCC's online documentation. I would like something that explains the more common and useful swithches and when/why to use them. If it goes into make at that same level of detail that would be a bonus.


Thanks
 

stevf

Senior member
Jan 26, 2005
290
0
0
thanks - that looks like it might be what I am looking for - I have seen that book and was thinking of getting it as it is reasonable priced and it looked like the book to have for GCC

Thanks again
 

degibson

Golden Member
Mar 21, 2008
1,389
0
0
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

 

stevf

Senior member
Jan 26, 2005
290
0
0
Thanks - that looks helpful too - I like a decent cheatsheet so you dont have to look up every single thing