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

16th Aug 2018, 7:50 PM
Saeed Vahid
Saeed Vahid - avatar
2 Réponses
+ 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) .
16th Aug 2018, 8:29 PM
Vlad Serbu
Vlad Serbu - avatar
0
both of them are in machine language but why .obj file isn't executable
16th Aug 2018, 7:51 PM
Saeed Vahid
Saeed Vahid - avatar