Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

[SOLVED] why object file is needed to generate executable file?

Status
Not open for further replies.

shreyas_patel21

Full Member level 3
Joined
Jan 4, 2011
Messages
181
Helped
15
Reputation
30
Reaction score
14
Trophy points
1,298
Activity points
2,325
hi all,

when we compile a code it generates object file and from those object files executable files are generated in linking process.

why we need object file?
what is the use of object file?
cant it be possible that executable file is generated directly?
after all we are using executable file to run the program.

thank you,
Regards,
Shreyas.
 

shreyas_patel21

Full Member level 3
Joined
Jan 4, 2011
Messages
181
Helped
15
Reputation
30
Reaction score
14
Trophy points
1,298
Activity points
2,325
hi all,

I got the answer

here it is:

Object files are what the linker uses to build complete executables (or libraries).

You can usually have your compiler output an executable "directly", the syntax will depend on the compiler. For instance with GCC:

gcc foo.c bar.c ...

will produce an executable and no intermediate object file will remain (but one will probably have been generated - and subsequently deleted).

Object files are used to make an incremental build. You compile each source file (or group of source files) to object files, then link all of them together in an executable. This allows you to only re-compile the source files that have changed since the last time you built, saving potentially a lot of time.
Or you could use the same object files to link different executables (re-use parts of your build to generate both an executable and a shared library for instance), again saving time and resources compared to compiling everything every time.

Object files aren't "needed" from a theoretical point of view. They're just very practical (and actually necessary technically with some (most?) toolchains, being the things the assembler knows how to produce and the linker knows how to link).

Regards,
shreyas.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top