Home  >  Q&A  >  body text

c++ - Makefile文件修改后,编译程序是否需要重新clean后,编译?

Makefile文件修改后,编译程序是否需要重新clean后,编译?

可否从Makefile的工作原理上剖析一下 ,是否每次都需要对工程代码,修改->make clean->make -j

巴扎黑巴扎黑2765 days ago631

reply all(1)I'll reply

  • 巴扎黑

    巴扎黑2017-04-17 11:32:07

    Makefile is basically a bunch of dependencies:

    target : dependencies
        action
    

    To put it simply, make will check whether the dependencies and target are new or old. If the target is older, then the action will be executed.
    For a typical program, the target is mostly an executable program or object file, the dependencies are mostly source code (maybe header files, etc.), the actions are mostly compilation commands, such as gcc -o $@ $^, and the Makefile itself is rarely appears in this dependency relationship.
    From this point of view, your changes to the Makefile may have no impact on the target itself. Remake is not necessarily necessary, but it is possible that your changes to the Makefile have caused changes in dependencies. In this case, you may need to start over. Again.

    reply
    0
  • Cancelreply