What is stdafx.h




















Your program comprises multiple modules, all of which use a standard set of include files and the same compilation options. In this case, all include files can be precompiled into one precompiled header. The first compilation — the one that creates the precompiled header PCH file — takes a bit longer than subsequent compilations. Subsequent compilations can proceed more quickly by including the precompiled code.

These header files can later be included in programs that use the class. By precompiling these headers, you can reduce the time a program takes to compile. Although you can use only one precompiled header. Precompiling requires planning, but it offers significantly faster compilations if you precompile source code other than simple header files. Precompile code when you know that your source files use common sets of header files but don't include them in the same order, or when you want to include source code in your precompilation.

Because PCH files contain information about the machine environment as well as memory address information about the program, you should only use a PCH file on the machine where it was created.

When you use a PCH file, the compiler assumes the same compilation environment — one that uses consistent compiler options, pragmas, and so on — that was in effect when you created the PCH file, unless you specify otherwise. If the compiler detects an inconsistency, it issues a warning and identifies the inconsistency where possible. Such warnings do not necessarily indicate a problem with the PCH file; they simply warn you of possible conflicts.

Consistency requirements for PCH files are described in the following sections. The state of defined constants is not checked, but unpredictable results can occur if these change. If this option is in effect when the PCH file is created, subsequent compilations that use the PCH file can use the debugging information. If the C 7. The debugging information is placed in the current. A PCH file does not contain information about the include path that was in effect when it was created.

When you use a PCH file, the compiler always uses the include path specified in the current compilation. Pragmas processed during the creation of a PCH file usually affect the file with which the PCH file is subsequently used. The comment and message pragmas do not affect the remainder of the compilation.

These pragmas are retained as part of a precompiled header, and affect the remainder of a compilation that uses the precompiled header:.

Be sure to specify an environment consistent with the previous one using consistent compiler options, pragmas, and so on for the current compilation. Such warnings don't necessarily indicate a problem with the PCH file; they simply warn you of possible conflicts. The following sections explain the consistency requirements for precompiled headers. In You have added into stdafx. Or you could have included an auto-generated file by mistake. The debugger reports something strange.

It might have been caused by some faults related to the time of file modification. But it is possible, and you should be aware of it. Personally I have faced this issue only 2 or 3 times during the many years of my career. It can be solved by complete full project recompilation. By the way, you can download PVS-Studio and check your program for errors.

As you can see, working with precompiled headers is pretty easy. We hope this article has helped you to overcome that misunderstanding. Precompiled headers are a very useful option, which allow you to significantly enhance project compilation speed. Thanks for this insight. One drawback I can see already, though. Like Like. Great article. Like Liked by 1 person. I inherited a solution that has several stdafx.

Is there a way we can force all projects to use only one common stdafx. In addition you can find more information in my reply for Mr. Hope this will help you. Thanks for your great explanation. Now my precomiled header gets deleted whenever I compile a project that is supposed to use it. This is bothering me for some time now, Google does not yield any help at all so far. Do you have any ideas? In fact, you need to check 2 combinations of flags on your translation units.

When working, stdafx. Path in flags must match. Proceeding from this, try to do the following:. This will generate a precompiled header file. Set it by two ways: -Right click on stdafx. Do similarly to the steps 1 and 2. Thank you so much for this! I have annoying situation with StdAfx. But project compiles. So, if I include right path to stdafx. If I include wrong path to stdafx. It is very, very annoying. You are commenting using your WordPress.

You are commenting using your Google account. You are commenting using your Twitter account. You are commenting using your Facebook account. Notify me of new comments via email. Notify me of new posts via email. This site uses Akismet to reduce spam. Learn how your comment data is processed.

Case Otherwise, there is no need to use stdafx. And this does not means that you will remove it from your project, but you can disable this precompiled header of project settings, by selecting the file where you do not need this stdafx.

Toggle navigation. What is "stdafx. Navigation 1 by 6 votes 2 by 6 votes. When removing this line, I get the following error error C unexpected end of file while looking for precompiled header.

What is the purpose of this line? You can disable this in Visual Studio, but the build will slow down. By default Stdafx. Code: include "stdafx.



0コメント

  • 1000 / 1000