www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - The .obj file, what is it?

reply I =?UTF-8?B?TGluZHN0csO2bQ==?= <nota.real address.com> writes:
So, a question from a beginner. What is the .obj file that 
appears after the source is compiled into the executable? I can't 
find a good explanation on the Net for it. I take it the file has 
to accompany the executable for the program to function since the 
online explanations I've found say it contains instructions and 
is related to memory management? It's been bugging me from the 
start.
May 03 2017
next sibling parent reply Stanislav Blinov <stanislav.blinov gmail.com> writes:
On Wednesday, 3 May 2017 at 10:55:44 UTC, I Lindström wrote:
 So, a question from a beginner. What is the .obj file that 
 appears after the source is compiled into the executable? I 
 can't find a good explanation on the Net for it. I take it the 
 file has to accompany the executable for the program to 
 function since the online explanations I've found say it 
 contains instructions and is related to memory management? It's 
 been bugging me from the start.
The source is not compiled into the executable. The source is compiled into a "object code", output into an "object file" - in this case, the .obj file. Afterwards, object files are linked by a linker (usually also taking other object files and/or libraries) to produce an executable or a library. .obj files are not needed to be redistributed, they've served their purpose when the final target executable or library has been created. But it's useful to keep them in the development environment, as usually the build environment would not spend time recompiling the code when an up-to-date object files are present.
May 03 2017
parent I =?UTF-8?B?TGluZHN0csO2bQ==?= <nota.real address.com> writes:
On Wednesday, 3 May 2017 at 11:09:33 UTC, Stanislav Blinov wrote:
 The source is not compiled into the executable. The source is 
 compiled into a "object code", output into an "object file" - 
 in this case, the .obj file. Afterwards, object files are 
 linked by a linker (usually also taking other object files 
 and/or libraries) to produce an executable or a library.
 .obj files are not needed to be redistributed, they've served 
 their purpose when the final target executable or library has 
 been created. But it's useful to keep them in the development 
 environment, as usually the build environment would not spend 
 time recompiling the code when an up-to-date object files are 
 present.
Ohhhhhhhh... Many thanks. This cleared it for me. What happens at compile time is all magic to me still, but learning as I go.
May 03 2017
prev sibling parent Adam D. Ruppe <destructionator gmail.com> writes:
Basically, .obj is a temporary file the compiler uses to store 
its half-finished work on the way to producing the exe.

Once you have the exe, the obj is no longer necessary, but 
keeping them around can sometimes speed up recompiles by reusing 
the left over work from last time. (Not so much in D though, this 
more applies to C.)
May 03 2017