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?
The file contains binary data which must be run through a linker to generate an executable. It is essentially a bunch of machine code instructions with named sections (corresponding to your functions).
Object files define and reference symbols, where each symbol corresponds to a function, a global variable, or a static variable (i.e., any C variable declared with the static attribute). The purpose of symbol resolution is to associate each symbol reference with exactly one symbol definition.
The OBJ file format is a text file format, which means you can edit OBJ files in a text editor if you are hard-core.
(Computers) A computer program which has been translated into machine language by a compiler and assembler, but not yet linked into an executable program; sometimes called an obj file, because its file name typically has the extension "obj" . Webster's Revised Unabridged Dictionary, published 1913 by G.
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.
There are several standardized formats (COFF, ELF on Unix), basically they are variants of the same formats that those used for executables but missing some informations. These missing informations will be completed when linking.
Objects files formats basically contains the same informations:
When objects will be linked together the parts of the code that refers to external symbols will be replaced by actual values (well, that is still oversimplified, there is a last part that will be done at loading time when running the program, but that's the idea).
The object file may also contain more symbols information that strictly necessary for resolving imports and export (useful for debug). That information can be removed using the strip command.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With