What Is .o file
Content on WhatAnswers is provided "as is" for informational purposes. While we strive for accuracy, we make no guarantees. Content is AI-assisted and should not be used as professional advice.
Last updated: April 11, 2026
Key Facts
- .o files were first standardized with the Unix C compiler in the 1970s-1980s
- A typical C program compilation generates one .o file per .c source file
- ELF (Executable and Linkable Format) became the standard .o file format on Linux in 1995
- .o files typically occupy 2-10x the size of their source .c files due to debug symbols
- Modern projects with 1,000+ source files can generate 1,000+ .o files during compilation
Overview
A .o file is an object file produced by a compiler as an intermediate artifact during the software compilation process. When you compile source code written in languages like C or C++, the compiler translates human-readable code into machine-executable instructions and stores the result in a .o file. This file contains compiled binary code, along with metadata about functions, variables, and their locations in memory.
Object files serve as a bridge between your source code and the final executable program. Rather than compiling all source files directly into one executable, modern build systems compile each source file into its own .o file, then use a linker to combine these files with libraries to create the final executable. This approach enables incremental compilation, where only modified source files need recompilation, significantly speeding up development cycles for large projects.
How It Works
The creation and use of .o files follows a well-defined process in the software development workflow:
- Compilation Step: When the compiler processes a .c or .cpp source file, it generates a corresponding .o file containing the compiled machine code. This file uses the native binary format for your operating system, such as ELF on Linux, Mach-O on macOS, or COFF on Windows.
- Symbol Table Storage: Each .o file includes a symbol table that lists all function names, variable names, and their memory offsets. This allows the linker to locate and connect symbols referenced across different object files when building the executable.
- Relocation Information: The .o file contains relocation entries that specify which parts of the code need address adjustments during linking. This enables the linker to resolve references to external functions and variables not yet assigned final memory addresses.
- Section Organization: Object files are divided into sections like .text (code), .data (initialized variables), .bss (uninitialized variables), and .debug (debugging information). This organization helps the linker place code and data at appropriate memory locations in the final executable.
- Linking Process: During the linking phase, the linker reads multiple .o files and combines them with standard libraries, resolving all symbol references and producing the final executable or shared library. The linker discards unreferenced code and optimizes memory layout.
Key Comparisons
| Aspect | .o File (Object) | .c File (Source) | Executable |
|---|---|---|---|
| Human Readable | No (binary format) | Yes (plain text) | No (binary format) |
| Contains Symbols | Yes, with relocation info | Yes, as text | Yes, with resolved addresses |
| File Size Ratio | 2-10x larger than source | 1x (baseline) | Varies; often smaller than all .o files combined |
| Can Be Executed | No (incomplete) | No (not compiled) | Yes (complete and linked) |
| Created By | Compiler | Developer/Editor | Linker |
Why It Matters
- Incremental Compilation: By storing compiled code in .o files, build systems only recompile changed source files, reducing build times from hours to minutes for large projects with thousands of files.
- Modularity and Reusability: Object files enable code modularity by allowing developers to compile library code once and link it into multiple programs without recompilation, forming the basis of static libraries (.a files) and dynamic libraries (.so, .dll files).
- Debugging Support: .o files preserve debugging symbols that map machine code back to source lines, enabling debuggers to set breakpoints, inspect variables, and trace execution paths back to the original source code.
- Static Linking Foundation: Static libraries are collections of .o files archived together; understanding .o files is essential for grasping how static linking works and how symbol resolution occurs during the build process.
Object files represent a critical concept in compiled language development. They enable efficient compilation workflows, support code reuse through libraries, and form the foundation of modern build systems. Whether working with C, C++, Rust, or other compiled languages, understanding how .o files are generated, organized, and linked into executables is essential for debugging build issues, optimizing compilation speed, and managing large codebases effectively.
More What Is in Daily Life
Also in Daily Life
More "What Is" Questions
Trending on WhatAnswers
Browse by Topic
Browse by Question Type
Sources
- Wikipedia - Object FileCC-BY-SA-4.0
- Wikipedia - ELF FormatCC-BY-SA-4.0
Missing an answer?
Suggest a question and we'll generate an answer for it.