Search code examples
cgccltotranslation-unit

Are multiple source files being passed to gcc treated as a single translation unit?


I think I've read that compiling multiple files with gcc at the same time would achieve the same thing as adding all sources into a single source file, as per Single Compilation Unit, but I can't find any sources on that anymore. Is that true?

We are currently trying to shrink a binary to the smallest size possible and are applying multiple techniques to achieve that. We reached the point where the discussion is about the differences between Single Compilation Unit, Link Time Optimization and changing the build to compile all sources in a single compiler call, something like gcc -o binary $CFLAGS $INCLUDES $CDEFS a.c b.c c.c d.c e.c.


Solution

  • No. Each independent .c file passed to a compiler is considered a single translation unit, so multiple files passed to a compiler produce multiple independent translation units.