[英]How can find out how much time a C++ header takes to compile in Visual Studio?
I'm looking for a way to tell Visual Studio run a specific header file through the compiler. 我正在寻找一种方法来告诉Visual Studio通过编译器运行特定的头文件。 This is for purely for hunting and keeping compilation time down. 这纯粹是为了狩猎和保持编译时间。
What I can think of is to create a .cpp file, which includes said header. 我能想到的是创建一个.cpp文件,其中包含所述标题。 However, it's very cumbersome to create a file and then Ctrl-F7
to compile that .cpp file when you have many headers you want to check the compilation time with. 但是,如果有多个标题需要检查编译时间,那么创建一个文件然后Ctrl-F7
来编译该.cpp文件非常麻烦。
Is there a way to tell Visual Studio to compile the current open header with Ctrl-F7
? 有没有办法告诉Visual Studio使用Ctrl-F7
编译当前打开的标题?
Note: This is not a question on how to use header files. 注意:这不是关于如何使用头文件的问题。
It makes no sense to compile a header which is not included in a cpp file, therefore it's not possible. 编译一个未包含在cpp文件中的标头是没有意义的,因此它是不可能的。
You may want to have a look at creating so called precompiled headers though, which can help with compilation times. 您可能希望看一下创建所谓的预编译头文件 ,这可以帮助编译时间。
A header file is a file supposed to be included in a cpp file, which technically is the actual source code file, what we call officially a "compilation unit". 头文件是一个应该包含在cpp文件中的文件,从技术上讲它是实际的源代码文件,我们称之为“编译单元”。
So your header file actually only contain code "included" in another file. 所以你的头文件实际上只包含另一个文件中的“包含”代码。 That inclusion is technically a copy/paste into the file doing the inclusion. 从技术上讲,这种包含是复制/粘贴到包含的文件中。 Headers might include each other but in the end, only the compilation unit - the cpp file - is actually compiled. 标题可能包含彼此,但最后只编译单元--cpp文件 - 实际编译。
Headers are not compilation units. 标题不是编译单元。 Header files don't actually exist for a compiler; 头文件实际上并不存在于编译器中; they are just files from where they copy paste code inside what they read from a compilation unit. 它们只是从他们从编译单元读取的内容中复制粘贴代码的文件。
This mean that, if you want to check if a header does compile, you have to include it somewhere in a compilation unit (even an empty .cpp file will do) and let the compiler compiler that compilation unit. 这意味着,如果要检查标头是否编译,则必须将其包含在编译单元中的某处(即使是空的.cpp文件也可以)并让编译器编译该编译单元。
OR you could rename the header file so that it is recognized as a compilation unit (by changing it's extension to .cpp). 或者您可以重命名头文件,以便将其识别为编译单元(通过将其扩展名更改为.cpp)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.