1
votes

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
Do you have #include "xxxx.cpp" in a cpp file? - NathanOliver
Yes, yes, exactly. How the compiler should handle it? - Narek
As a general rule one should only ever include header files. see this: programmers.stackexchange.com/questions/254233/… - NathanOliver
@NathanOliver I have used Include Guards in my .cpp files why defining my classes, so there can be no problem of a redefinition, as the answer in your link states. - Narek
I'm just stating that it flies against the standard coding practice. SOP is to have headers with declaration and cpp files with definitions. You include all the pertinent headers in the cpp files as need and then you compile all of the cpp files into object files and then link them all together. You don't have to do it that way but it is the way the majority of C++ is written. - NathanOliver

1 Answers

5
votes

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.