C compiler flags for build debugging

I’ve been working on compiling a particularly recalcitrant C program recently, about which more later.  A large part of the difficulty is that I’m also having to learn the how to get enough output from the C compiler (in this case GCC) to figure out exactly what is going wrong.

Here are some compiler flags that make this easier:

-v for “verbose” output, prints compiler version information, the exactly command line used by Make to invoke the compiler.  It also prints the list of search paths used for #include directives, which is extremely useful.

​​​​​​​​​​​​-​H to print the full name of every included header file, so you can figure out exactly which version of stdio.h is missing the L_cuserid definition.

Running make with -jn to run multiple builds in parallel makes this sort of output very confusing, because the output from different builds is interleaved in no particular order.  I solved this by running make -j4 to get a quick but impossible to read build, then just make to give one build with a clean log.  The second build is fast because it is incremental, only the parts of the system that failed to build the first time will be recompiled.

Leave a comment