Single compilation unit

Single compilation unit (SCU) is a computer programming technique for the C and C++ languages, which reduces compilation time for programs spanning multiple files.

This reduces the overall build time, due to eliminating the duplication, but increases the incremental build time (the time required after making a change to any single source file that is included in the SCU), due to requiring a full rebuild of the entire unit if any single input file changes.

[2] Therefore, this technique is appropriate for a set of infrequently modified source files with significant overlap (many or expensive common headers or templates), or source files that frequently require recompilation together, such as due to all including a common header or template that changes frequently.

[3] Another disadvantage of SCU is that it is serial, compiling all included source files in sequence in one process, and thus cannot be parallelized, as can be done in separate compilation (via distcc or similar programs).

For example, if you have the source files foo.cpp and bar.cpp, they can be placed in a Single Compilation Unit as follows: Suppose foo.cpp and bar.cpp are: Now the standard header file (iostream) is compiled only once, and function bar may be inlined into function main, despite being from another module.