EffessDev uses a two-file greeting program in the DEV article Why Can't We Just #include "functions.c" in "main.c"? 🤔 to explain what a compiler needs to know before it can generate a call to a function implemented in another file.
Give the caller a declaration
In the example, main.c calls greet(), whose definition lives in functions.c. A declaration such as void greet(void); tells the compiler that the function takes no arguments and returns no value. Putting that declaration in functions.h gives callers a shared place to get the signature. The implementation file can include the same header so the compiler also sees the declaration when checking the definition.
The example builds both sources with gcc main.c functions.c -o final_program. The compiler can process the two source files as separate translation units. Once each has been compiled, the linker resolves the reference from the caller using the definition from the implementation. That division of work still applies when the compiler handles the files one at a time.
What changes when a source file is included
An include directive brings the included file into the preprocessing input for the current translation unit. Including functions.c therefore brings the definition along with it. For the greeting example, that can work if the program is built as a single translation unit. If another separately compiled translation unit also includes the same implementation, linking can fail because both object files contain a definition of the same externally visible function. An include guard operates within each translation unit, so it cannot prevent that error across object files.
Separate compilation also gives a build system a way to rebuild selectively. A build that tracks file dependencies can recompile functions.c after a change to its implementation, reuse the existing object for main.c, and relink. The two-source GCC command in the example invokes compilation for both inputs on each run. The reuse comes from the incremental build rules.
GCC preprocessing documentation and GCC compilation options describe the two stages in more detail.