我最近有理由使用通常的调试和发布配置以及我以前从未见过的全部发布"和全部调试"来处理一些 Visual Studio C++ 项目.
I recently had cause to work with some Visual Studio C++ projects with the usual Debug and Release configurations, but also 'Release All' and 'Debug All', which I had never seen before.
事实证明,项目的作者有一个 ALL.cpp,其中 #includes 所有其他 .cpp 文件.*All 配置只是构建这个 ALL.cpp 文件.它当然被排除在常规配置之外,常规配置不构建ALL.cpp
It turns out the author of the projects has a single ALL.cpp which #includes all other .cpp files. The *All configurations just build this one ALL.cpp file. It is of course excluded from the regular configurations, and regular configurations don't build ALL.cpp
我只是想知道这是否是一种常见做法?它带来什么好处?(我的第一反应是它闻起来很糟糕.)
I just wondered if this was a common practice? What benefits does it bring? (My first reaction was that it smelled bad.)
您可能会遇到哪些陷阱?我能想到的一个问题是,如果您的 .cpps 中有匿名命名空间,它们不再是该 cpp 的私有"名称,但现在在其他 cpp 中也可见?
What kinds of pitfalls are you likely to encounter with this? One I can think of is if you have anonymous namespaces in your .cpps, they're no longer 'private' to that cpp but now visible in other cpps as well?
所有项目都构建 DLL,所以在匿名命名空间中保存数据不是一个好主意,对吧?但是功能就可以了吗?
All the projects build DLLs, so having data in anonymous namespaces wouldn't be a good idea, right? But functions would be OK?
它被一些人(和 google-able)称为Unity Build".它的链接速度非常快,编译速度也相当快.它非常适合您不需要迭代的构建,例如来自中央服务器的发布构建,但不一定适用于增量构建.
It's referred to by some (and google-able) as a "Unity Build". It links insanely fast and compiles reasonably quickly as well. It's great for builds you don't need to iterate on, like a release build from a central server, but it isn't necessarily for incremental building.
这是一个需要维护的 PITA.
And it's a PITA to maintain.
这是获取更多信息的第一个谷歌链接:http://buffered.io/posts/the-magic-of-unity-builds/
here's the first google link for more info: http://buffered.io/posts/the-magic-of-unity-builds/
使其快速的原因是编译器只需要读入所有内容,编译出来,然后链接,而不是对每个 .cpp 文件都这样做.
The thing that makes it fast is that the compiler only needs to read in everything once, compile out, then link, rather than doing that for every .cpp file.
Bruce Dawson 在他的博客上写得更好:http://randomascii.wordpress.com/2014/03/22/make-vc-compiles-fast-through-parallel-compilation/
Bruce Dawson has a much better write up about this on his blog: http://randomascii.wordpress.com/2014/03/22/make-vc-compiles-fast-through-parallel-compilation/
这篇关于#include 所有 .cpp 文件到一个编译单元?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!