In programming if we compile the source code to an object file that is in machine language why yet it cannot be run in our os? | Sololearn: Learn to code for FREE!

0

In programming if we compile the source code to an object file that is in machine language why yet it cannot be run in our os?

difference between .exe and .obj

8/16/2018 7:50:35 PM

Saeed Vahid

2 Answers

New Answer

+1

Because they are different formats. The OS knows how to execute an .exe file because it starts with a header that gives it some information about it (preferred memory location, etc). Moreover, in the obj file, gotos (jumps) don't refer to actual address of the target instruction, but to a label. If your program has more than one source file, it will generate multiple cross-referenced source files (a jmp label5 may appear in a.obj, but label5 itself may be in c.obj), which are to be merged together in a later stage of compilation. There are many more differences, but in essence, the obj files aren't yet fully compiled. On the Plan 9 From Bell Labs OS, all .obj files (there .o files) were portable, meaning you could take them and build binaries for both x86 and MIPS systems (which obviously have different instruction sets, and, as such, different binary file formats) .

0

both of them are in machine language but why .obj file isn't executable