简体   繁体   English

如何找出C ++头在Visual Studio中编译需要多长时间?

[英]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.

相关问题 Visual Studio C ++枚举需要很长时间才能编译 - Visual Studio C++ enum takes a long time to compile 如何知道C / C ++代码中每行花费的时间? - How can I find out how much time is spend on each line in C/C++ code? 如何在C ++项目中的编译时使用Visual Studio宏 - How to use Visual Studio Macros at compile time in a c++ project 在 Visual Studio C++ 中,如何快速找到必要的头文件? - In Visual Studio C++, How to quickly find necessary header files? 在Visual Studio中的编译时查找C ++平台目标 - Find C++ platform target at compile time in visual studio 如何在visual studio中编译c ++文件? - How to compile c++ file in visual studio? 如何在Visual Studio C ++调试器中找到调试对象进程的基址? - How can I find out the base address of a debuggee process in Visual Studio C++ debugger? 如何知道我的c ++应用程序在Mac上使用了多少内存 - How can I find out how much memory my c++ app is using on the Mac 我如何找出一个C ++类实例消耗多少内存? - How can I find out how much memory an instance of a C++ class consumes? 如何在Visual Studio 2017 C ++中的编译时检查环境变量的存在? - How to check existence of environment variables at compile time in Visual Studio 2017 C++?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM