Home  >  Q&A  >  body text

c++代码在什么情况下,修改了代码,可以不需要编译?直接进行链接运行哦?

这是我看书的时候,想到的一个问题。不懂为什么某种情况下不需要编译代码也行(之前编译过,然后修改),平时自己修改了代码,都是要重新编译运行的。

ringa_leeringa_lee2765 days ago894

reply all(4)I'll reply

  • ringa_lee

    ringa_lee2017-04-17 13:40:53

    Does not need to be compiled refers to files that are not related to modifications.
    For example, there are the following files:
    common.h, file1.h, file1.c, file2.h, file2.c.
    Among them, common.h and file1.h are included in file1.c, and only file2.h is included in file2.c.
    After compilation, file1.c outputs the link file file1.o, and file2.c outputs the link file file2.o.
    So if common.h is modified, both file1.c and file2.c need to be recompiled, but if only file1.h is modified, only file1.c needs to be recompiled. This is what the book says.

    Oh, to add, compilation only generates link files (such as the .o file mentioned above). The executable file is finally generated after linking. Modifying the source code will cause the executable program to be regenerated (that is, re-generated). link), but not all link files will be regenerated, in other words, not all .c files will be recompiled.

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 13:40:53

    How to run without compiling

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 13:40:53

    If you change the code in C++, you need to recompile and run it. Unless you change it and then change it back to the code before compilation, and the IDE also has this recognition function, then maybe you don’t need it!

    reply
    0
  • 迷茫

    迷茫2017-04-17 13:40:53

    I understand that the "no need to compile" you are talking about here is that if other libraries are referenced in the project, then when the internal implementation (.c/.cpp) of these libraries changes, but the interface (.h) does not change , the project does not need to be recompiled (but the changed libraries need to be recompiled anyway), you only need to link the new libraries.

    reply
    0
  • Cancelreply