Why not all cpp files recompile?

吃可爱长大的小学妹 提交于 2019-12-24 15:12:32

问题


In visual studio 2015 community version I do a debug build with the following file structure.

A.cpp B.cpp that includes A.cpp C.cpp that includes A.cpp and B.cpp main.cpp that includes A.cpp, B.cpp and C.cpp

So when I change A.cpp in debug mode I get recompiled only A.cpp and main.cpp, but when I go to Release build mode, I get recompiled only A.cpp. Also I get some messages like:

In Release mode compile: 0 of 17 functions ( 0.0%) were compiled, the rest were copied from previous compilation.

In Debug Mode Compile: Skipping... (no relevant changes detected)

I was expecting to get recompiled all files as I include A.cpp in all files, and I changed it.

P.S. I know it is wired to include .cpp file but this is just some experiment, that I would like to understand how it works.


回答1:


Visual Studio minimal rebuild works at a finer granularity than per-file. If you just change the contents of a non-inline function but the signature remains the same, the Visual C++ toolchain can sometimes avoid recompiling things, even though they included a file that changed.

File modification times are still needed to decide what to parse, but the compiler then applies AST-level dependencies -- if the token stream matches the previous version and none of the AST-level inputs have changed, the compiler can reuse the previously generated object code for that function instead of repeating the optimization steps.



来源:https://stackoverflow.com/questions/36898357/why-not-all-cpp-files-recompile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!