所有的#include .cpp文件到一个单一的编译单元? [英] #include all .cpp files into a single compilation unit?

查看:321
本文介绍了所有的#include .cpp文件到一个单一的编译单元?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近有导致某些Visual Studio的C ++项目工作与通常的调试和Release配置,而且全部释放和所有调试,这是我以前从未见过。

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其中#包括所有其他.cpp文件。在*所有配置只是建立这一个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,但现在在其他CPPS可见呢?

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,在匿名的命名空间所以有数据不会是一个好主意,对吧?但是功能会OK?

All the projects build DLLs, so having data in anonymous namespaces wouldn't be a good idea, right? But functions would be OK?

干杯。

推荐答案

它是由一些简称(和谷歌能)作为团结构建。它链接速度飞快,合理快速编译为好。这是伟大的建立不需要迭代,喜欢从中央服务器发布版本,但它不一定是对增量建设。

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.

编辑:这是第一个谷歌链接了解更多信息:<一href=\"http://buffered.io/posts/the-magic-of-unity-builds/\">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.

布鲁斯·道森有一个更好的写了这个在他的博客:<一href=\"http://randomascii.word$p$pss.com/2014/03/22/make-vc-compiles-fast-through-parallel-compilation/\">http://randomascii.word$p$pss.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文件到一个单一的编译单元?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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