How can I make gcc do this…

This post will be dedicated to gcc’s command line options and various other questions related to compiling/building your code with gcc. For example…
——————–
How can I get gcc to generate assembly code for my C file:
gcc -O2 -S -c foo.c
——————–
How can I tell gcc to generate an assembly listing? (that is C and ASM instructions interspersed, and also displaying the byte offsets and line numbers):
gcc -c -g -Wa,-a,-ad $(DCEAPP_CFLAGS) db.c > db.LST
——————–
To test if my 64-bit gcc can produce 32-bit binaries:
gcc -m32 -pedantic-errors -std=c89 -Wall hello-world.c
——————–
To trace where the headers files are included from:
Option 1: Output a list of headers included (full paths):
gcc -c -M test.c &> gcc-output.txt

Option 2: Actual trace output, showing which headers include which other headers
gcc -c -E -x c - -v < test.c &> gcc-output.txt
gcc -c -E -x c++ - -v < test.cpp &> gcc-output.txt

2 thoughts on “How can I make gcc do this…

  1. To see default include and lib directories:
    gcc -v source_file.c

    The key part is giving it a source file (any C file) – otherwise it will only print version info and exit.

Leave a Reply to Alan Cancel reply

Your email address will not be published. Required fields are marked *