c++cgcccompilationobject-files

What does an object file contain?


During the various stages of compilation in C or C++, I know that an object file gets generated (i.e., any_name.o file). What does this .o file contain? I can't open it since it's a binary file.

Could anybody please help me? Are the contents of the object file mainly dependent on the compiler which we use on Unix?


Solution

  • Object files can contain a bunch of stuff: Basically it's some or all of the list below:

    The linker turns a bunch of object files into an executable, by matching up all the imports and exports, and modifying the compiled code so the correct functions get called.