I'm looking for a way to tell Visual Studio run a specific header file through the compiler. 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. 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.
Is there a way to tell Visual Studio to compile the current open header with 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.
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".
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.
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.
OR you could rename the header file so that it is recognized as a compilation unit (by changing it's extension to .cpp).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.