为什么不重新编译所有cpp文件? [英] Why not all cpp files recompile?

查看:215
本文介绍了为什么不重新编译所有cpp文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在visual studio 2015社区版本中,我使用以下文件结构进行调试构建。

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

A.cpp
包含A.cpp的B.cpp
包含A.cpp和B.cpp的C.cpp
main.cpp包括A.cpp,B.cpp和C.cpp

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

因此,当我在调试模式下更改A.cpp时,我仅重新编译了A.cpp和main.cpp,但是当我进入发布构建模式时,仅重新编译了A.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:

在发布模式下编译: 已编译17个函数中的0个(占0.0%),其余

在调试模式下编译: 跳过...(未检测到相关更改)

我希望重新编译所有文件,因为我在所有文件中都包含了A.cpp,并进行了更改。

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

P.S。我知道它已经包含了.cpp文件,但这只是一个实验,我想了解它的工作原理。

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.

推荐答案

Visual Studio最小化重建的粒度比每个文件都细。如果仅更改非内联函数的内容但签名保持不变,则Visual C ++工具链有时可以避免重新编译内容,即使它们包含已更改的文件也是如此。

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.

仍然需要文件修改时间来决定要解析的内容,但是编译器随后将应用AST级别的依赖关系-如果令牌流与先前版本匹配,并且所有AST级别的输入均未更改,则编译器可以重用先前为该函数生成的目标代码,而不是重复优化步骤。

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.

这篇关于为什么不重新编译所有cpp文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆