Why not all cpp files recompile?

2019-07-25 20:55发布

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条回答
趁早两清
2楼-- · 2019-07-25 21:33

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.

查看更多
登录 后发表回答