Build or compile

22,094

Solution 1

"Building" is a vague term that usually means the entire process, preprocessing, compiling and linking. Which parts of these processes have to be redone after a source change depends on what has changed. If you only changed a single .cpp source, it's enough to recompile it and link the objects again. If you change a .h header, all source files that include this header have to be recompiled, which is usually expensive as project-specific headers tend to be included in many source files.

In short, if you have made a change to the source, all files affected by this have to be recompiled and the entire binary has to be re-linked.

Solution 2

Compiling is the process of converting the high level code to machine level code

Building is the process of converting the high level language to a executable. It would involve compiling and linking .

In case of modification of a header file, the header file might affect several c++ files and hence to get a final executable you need to build it

There is no use in compiling alone as it does not produce the final excutable and hence you need to build always.

Solution 3

Build is the complete process of converting source code into an executable, for C++ compilation is the conversion of source code into object code. In a build the C++ code will be compiled and then you will need other stages including a link phase to construct an executable. Builds can also involve other steps e.g. preprocess or generating source code files before compilation.

Doing a build just in the cases in where "I have modified any header file" just means that only files that include (directly or via other included files) are compiled and then all objects are linked. Ina "full" build all files would be compiled so this will cut down on the number of files to be compiled and reduce the overall build time.

If you change a header file then you have to build, compiling would just create a new object file that is not yet part of the executable.

Solution 4

I am not sure I understood your question fully.

Compiling is only a part of the build process (which consists of preprocessing, compiling, linking, and possibly others). It creates object files which linker then links into an executable, so only compiling is not enough.

If your question is really whether you should run full build of your software, then sometimes you don't have to if you have only changed the implementation (.cpp) files, but if you have also changed declarations (i.e. headers) then you will most likely need to do it. In any case, you will have to fully build the affected component - not just compile it.

Solution 5

Compiling is just one of the steps in building. Any time you need to recompile, you will need to rebuild.

Compiling just takes the source files and their included header files and generates an object file for each source file. Building also links these files together to create your executable. So if you change a source file, you need to build if you want a new executable to test. Compiling will just get you part way there.

Share:
22,094
Frion3L
Author by

Frion3L

Updated on February 10, 2020

Comments

  • Frion3L
    Frion3L over 4 years

    I have a theoretical question about the difference between compile and build. I'm programming in a c++ project that takes a lot of time to build, so I have told to do build just in the cases in where "I have modified any header file". Is that true? If I add a new attribute in a headder file, then do I have to build? Is not enough compiling?

    Thanks!

  • jave.web
    jave.web about 9 years
    I would disagree with the last one - compiling alone HAS a use - sometimes you need to compile to check if the code is validly-compilable - you don't need to build because your app is not ready yet... or that part is just not intended to be directly for exe output...