Build or compile

后端 未结 6 942
终归单人心
终归单人心 2020-12-28 18:17

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

相关标签:
6条回答
  • 2020-12-28 18:23

    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.

    0 讨论(0)
  • 2020-12-28 18:25

    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.

    0 讨论(0)
  • 2020-12-28 18:26

    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.

    0 讨论(0)
  • 2020-12-28 18:30

    "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.

    0 讨论(0)
  • 2020-12-28 18:33

    Compiling is the act of turning source code into object code.

    Linking is the act of combining object code with libraries into a raw executable.

    Building is the sequence composed of compiling and linking, with possibly other tasks such as installer creation.

    taken from What is the difference between compile code and executable code?

    Therefore, you only need to (re-)compile object-code that is older ("has been edited more recently") than the source file to link an executable that contains the newest changes in your program. In fact, this is how make decides whether to build a file.

    0 讨论(0)
  • 2020-12-28 18:41

    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.

    0 讨论(0)
提交回复
热议问题