User:Ramesh.garimella

Difference between an executable file and object file

Both are binary files but the differences between those are:-

1) we can execute an executable file while we cannot execute an object file.

2) An object file is a file where compiler has not yet linked to the libraries, so you get an object file just before linking to the libraries, so still some of the symbols or function definitions are not yet resolved which are actually present in the libraries, and that's why we cannot execute it. Once an object file is linked with the library by the compiler, then all the symbols are resolved and we get an executable file which can be executed on the appropriate platform. So basically the difference is that we get an object file when we don't link with library while executable file is with the linking phase. In gcc we can direct compiler not to link with library and so it will prepare the object file :-

gcc -c test.c

It will automatically create test.o object file when you try to execute it like:-

./test.o

cannot execute binary file