This flag will compile the .c
code to binary without passing through the
linker first (default behaviour when no flags are passed).
This can be useful if you are using a different linker tool, or if you just want to see the assembly generated by a file that has external declarations.
For example:
// From CSAPP book
// > /tmp/main.c
long mult2(long, long);
void multstore(long x, long y, long*dest) {
long t = mult2(x, y);
*dest = t;
}
Running with defaults:
gcc /tmp/main.c -o /tmp/a.o
# /usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/14.1.1/../../../../lib/Scrt1.o: in function `_start':
# (.text+0x1b): undefined reference to `main'
# /usr/bin/ld: /tmp/ccdSRhTc.o: in function `multstore':
# main.c:(.text+0x23): undefined reference to `mult2'
# collect2: error: ld returned 1 exit status
But if we run the following:
gcc -c /tmp/main.c -o /tmp/a.o
no errors are raised.