简体   繁体   English

有没有一种方法可以在VS中构造预编译的标头,而又不会使我的代码难以在GCC中构建?

[英]Is there a way of structuring precompiled headers in VS that doesn't make my code awkward to build in GCC?

In the past I've used precompiled headers in VC to speed up compile times but usually only in smaller projects that are basically just a small directory of source code. 过去,我在VC中使用预编译的头文件来加快编译时间,但通常仅在较小的项目中使用,这些项目基本上只是源代码的一小部分。 Since VC++ requires that all files include the same header exactly regardless of path (say "foo.h" and not "../foo.h") things get hairy when you have different nested directories of source. 由于VC ++要求所有文件都完全包含相同的标头,而不管其路径如何(例如,“ foo.h”而不是“ ../foo.h”),所以当您具有不同的源嵌套目录时,事情就会变得繁琐。 If all my files just 如果我所有的文件只是

#include "foo.h" 

it works but only when I have precompiled headers on. 它有效,但仅当我预编译了头文件时才有效。 To make this work in all cases I need to make dummy foo.h files that go 为了在所有情况下都能正常工作,我需要制作虚拟的foo.h文件

#include "../foo.h"

This starts to get ridiculous pretty fast especially when you have multiple levels. 这开始变得非常荒谬,特别是当您具有多个级别时。

Even though I typically prefer Microsoft tools I have to say that GCC's system where you manually compile your headers into .gch files seems far superior to me. 尽管我通常更喜欢Microsoft工具,但我不得不说,在GCC的系统中,将标头手动编译为.gch文件似乎比我优越得多。 It is much less intrusive and doesn't require you to include all your headers in every compilation unit which is ugly and slow if you are building on a compiler without precompiled headers. 它的介入性要低得多,并且不需要您在每个编译单元中都包含所有标头,如果您是在没有预编译标头的编译器上构建的,则这是丑陋且缓慢的。

Am I missing something about the VC version? 我是否缺少有关VC版本的信息? None of the large projects I've worked on professionally have used precompiled headers and I want to make sure I give them a fair shake before I give up and just accept the longer compile times. 我专业从事的大型项目中没有一个使用预编译的头文件,因此我想确保在放弃之前接受公平的修改,只接受更长的编译时间。

Is there a cleaner way of doing this? 有没有更干净的方法可以做到这一点?

Thanks! 谢谢!

Is it possible to update project include path, so there is no need to create separate header. 是否有可能更新项目的包含路径,所以无需创建单独的标头。 We used header file Common/Common.h to create precompiled header in all projects. 我们使用头文件Common / Common.h在所有项目中创建预编译的头。

If the problem is compilation time, different approaches may address it: we removed precompiled headers from the project, as distributed compilation was significantly faster wihout them. 如果问题是编译时间,则可以采用不同的方法来解决:我们从项目中删除了预编译的头文件,因为分布式编译在没有头文件的情况下要快得多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM