πŸ˜„The files extension

Overview

In C/C++ projects, there are several file extensions that have specific meanings.

  • .h A header file that contains function prototypes, constant definitions, and other declarations that are needed by multiple source files.

  • .cpp A C++ source file that contains the implementation of classes and functions.

  • .c A C source file that contains the implementation of functions

  • .o An object file is generated by compiling a source file. It contains compiled code and data that will be linked with other object files to create an executable. (.obj extension in Windows systems)

  • .a is a static library file that is typically generated by the archive tool. It contains a collection of object files that have been compiled from C source code and assembled into a single file. It is used during the linking phase of the C project to resolve references to external functions and variables that are defined in the static library.

Detail of the linking process

The object file contains information about the symbols defined and used by the source file, which are necessary for resolving symbol references across multiple object files during linking. Object files are created for each source file before linking them together into the final executable.

And the linker resolves symbol references across multiple object files by matching symbol names in one object file with symbol definitions in another object file.

The linking process involves several steps, including:

  • symbol resolution

  • relocation

  • creation of the final executable or library

The output of the linker is an executable file or library that can be loaded into memory and executed(.o or .obj in Windows)

The symbol information

Symbol information in object files is metadata that holds information about the program's symbolic definitions and references.

It corresponds to a function, a global variable, or a static variable declared with the static attribute. And it includes the name of the symbol, its type, its size, and its location in memory. The location can be relative to the start of the section or the start of the file.

The symbol information is used by the linker to resolve symbol references across multiple object files and to generate the final executable or library. And it is stored in the symbol table of the object file, which is an associative data structure that maps symbol names to their attributes.

The symbol table contains information needed to locate and relocate the program's symbolic definitions and references. And it can be accessed using tools such as nm on Linux systems.

Reference

Last updated