Profile photo for Kundan Kamal

During compilation, the compiler often generates several temporary files, which it then deletes to clean up. Common ones are:

  1. C compilers first run the code through a preprocessor, and often use a temporary file to store the result.
  2. Almost all modern compilers reduce C to an intermediate language that can be better optimized. This is often stored in a temporary file.
  3. Old versions of gcc (possibly new versions, as well) would generate assembly, which was then assembled using gas (the GNU assembler). This step was done using a temporary file (with a .S extension).

The result of the compile phase then produces either one or two files:

  1. An object file (.o for most Unices, .obj for Windows) that contains compiled but unlinked code. This code cannot be executed; it has external dependencies (the system library, and possibly other libraries) that must be satisfied by a linking phase.
  2. If the user requests debugging information (-g under gcc), then, depending on the architecture and other compilation flags, the compiler may generate a file (or directory) that contains symbolic information used in debugging. The compiler in Mac OS X produces .dSYM directories that contain the debugging information. Under Linux, this is often embedded in the object (.o) file.

Finally, Mac, Unix, and Windows have a linking phase, which takes the object files (.o and .obj) and any required libraries (.a, and .so under Linux; .a, .dylib, or a framework under Mac OS X; .lib or .dll under Windows), and produces an executable. This is the phase that generates the executable (.exe under Windows) file.

To sum it up, when compiling an executable:

  • The C compiler often creates (and then deletes) a number of temporary files.
  • The C compiler generates one or more object files.
  • The linker generates an executable, and may also create (and delete) temporary files.
  • Some C compilers (e.g., gcc) also operate as front-end drivers for both the compiler and the linker. In this case, the compiler may delete any unneeded temporary files, such as the object files generated by the compilation phase.
View 4 other answers to this question
About · Careers · Privacy · Terms · Contact · Languages · Your Ad Choices · Press ·
© Quora, Inc. 2025