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.
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 It will not execute as BINARY file
No comments:
Post a Comment