Tip: cannot open include file: 'stdafx. H': no such file or directory
# Include "stdafx. H" before # include, that is, the beginning of the program. To use the precompiled header file, you need to put it at the beginning of the program, otherwise the content before it will be ignored.
-------------------------------------------------------------------------------
The way in which you have set up your workspace when creating a new project does not require the # include "stdafx. H", therefore delete this line (or comment it out ).
------------------------------------------------------------------------------
Precompiled header file (the general extension is. PCH) is to compile the more stable code in a project in advance and put it in a file (. PCH. these pre-compiled codes can be any C/C ++ code-or even inline functions, but they are relatively stable throughout the project, that is, the code that is not frequently modified during the project development process.
Why do we need to pre-compile the header file? In a word: it increases the compilation speed. generally, the compiler compiles files in units. If a file in a project is modified, all files must be re-compiled, including everything in the header file (eg. macro macro, Preprocessor preprocessing), while in VC programs, the content contained in these header files is often very large, and compilation takes a long time. but they are not often modified, and they are relatively stable. Re-compiling all files of the entire project for a single small file leads to a reduction in compilation efficiency, which is introduced. PCH file.
How to use pre-compiled header files to increase Compilation speed? To use a precompiled header file, you must specify a header file (. h), it contains the code that we do not often modify and other header files, and then use this header file (. h) generate a pre-compiled header file (. PCH) the default header file of VC is stdafx. h. Because the header file cannot be compiled, we still need one. CPP file as a bridge. The default VC file is stdafx. CPP, the only code in this file is: # include "stdafx. H ". use it to generate. the PCH file involves several important pre-compilation commands:/YU,/YC,/Yx,/FP. in short,/YC is used to generate. PCH file compilation switch. in the category of project-> setting-> C/C ++, select the precompiled header for compilation in the Tree View on the left. the. CPP file (default: stdafx. CPP) you can see the/YC switch, which indicates whether the file is generated after compilation. PCH file (possibly/YC c Represents create ). /FP command to specify the generated. the name and path of the PCH file (maybe/FP p represents path ). /Yu's U is used for use, as long as it is included in the project. this/YU command is available for all files in the H file. if you select automatic... the original/YC is replaced with the/Yx command. if Automatic is selected, the compiler will check whether it has been generated before each compilation. PCH file. If yes, it will not be generated. Otherwise, it will be compiled again. PCH file.
Note:
A. In fact, the default header file and CPP file stdafx generated by the appzard Project Wizard. H and stdafx. CPP can be any name. the reason is simple. but if you want to do this, remember to modify the corresponding project-> setting... parameters of several pre-compiled commands (/YC,/YU,/Yx,/FP.
B. it is used in any header file that includes the header file to be precompiled. the start of the project file of the PCH file must be at the beginning. You must include the specified file to be generated. the. h file (. the CPP file is included. The default value is stdafx. CPP), if not included, it will generate the first error. if it is not at the beginning, it will lead to unexpected and inexplicable errors. If you do not believe it, should it be a try?
C. pre-compiled file. PCH generation takes a lot of time, and it also occupies disk space after generation, usually 5-6 M. Note that it is useless to clean up after the project is completed. PCH file to save disk space.
D. if it is lost or deleted. when you need to modify the project file later. CPP file (default: stdafx. CPP) re-compile once to generate again. PCH file. Do not use F7 or rebuild all.
(It seems that this person is not very good at B's literary skills, but I have read this article many times ....
-By: Tie Gu)
----------------------------------------------------------------------------
Problem
This message appears during the compilation of Microsoft Visual? C ++ code generated by IBM rational? Rose? :
"Cannot open include file: 'stdafx. H': no such file or directory "?
Cause
As the error message says, the compiler is finding an Include statement for the header file "stdafx. H", but can't find the file itself.
Rose is generating the following line: # include "stdafx. H" by default.
# Include "stdafx. H"
The file stdafx. H is usually used as a precompiled header file. precompiled headers help to speed up compilation when a group of files in a project do not change.
Solution
If a precompiled header is not used, this include shouldn't get generated in the code. to turn it off, open the Visual C ++ component Properties dialog and in the tab "includes" Delete the text in the "initial source includes ".
Another possibility is to create an empty "stdafx. H" file.
For more information about precompiled header files, refer to the Microsoft Knowledge Base.
Bytes --------------------------------------------------------------------------------------------
# Include "stdafx. H "the function of this statement is to set stdafx in the directory of the project. h. This file is included in the program, and the error you encounter is because your project directory does not contain stdafx. h file
If this file is needed, Visual Studio will automatically generate one for you when you create a new project. Otherwise, you can remove # include "stdafx. H ".
Add the # include "stdafx. H" clause before many programs"
This statement is not required by every program
Header file pre-compilation refers to some of the MFC standard header files used in a project (such as Windows. h. afxwin. h) pre-compilation. Later, this header file will not be compiled and only the pre-compilation results will be used. This will speed up compilation and save time.
The precompiled header file is generated by compiling stdafx. cpp and named after the project name. Because the precompiled header file is suffixed with "PCH", the compilation result file is projectname. PCH.
The compiler uses the pre-compiled header file through a header file stdafx. h. The stdafx. h header file name can be specified in the project compilation settings. The compiler considers that all commands in the # include "stdafx. H "the previous code is pre-compiled, and it skips # include" stdafx. H "command, using projectname. PCH compiles all the code after this command.
Therefore, the first statement of all CPP implementation files is: # include "stdafx. H ".
Bytes -------------------------------------------------------------------------------------------
To put it simply, stdafx. h and precompile header are related. If you set whether to use the procompile header in the compiler environment, you can ignore stdafx. h/. cpp. However, for large programs in zookeeper, using the precompile header will save some time (precompile header first checks frequently used library sources that are not often changed, just as creating them first. same as Lib, but the source may change, and the precompile header can be updated)
Some minor questions! Please ask:
(1 ).
Is. PCH merge a precompile header? So what is the difference between it and stdafx. h.
(2 ).
When I set the option in Project/setting, I want to select the option!
Automatic use of precompile Headers
Create precompile header file [. PCH]
Use precompile header file [. PCH]
Is there a. PCH option that requires inserting projectname. PCH? What is the relationship between it and stdafx. h?
(3 ).
There is also a huge margin:
"First obtain a portion of the commonly used standard C ++ Library (such as STL) in the precompile header to increase the efficiency of zookeeper 』
What should we do?
Are those iostream. H, vector. H, and list. H put in the precompile header?
Where is that?
Too many!
--------------------------------------------------------------------------------
(1)
. PCH is the product of stdafx. H is used to define the place where users need to renew their resources first, but I mentioned earlier that this is the use of VC, we cannot see that every browser uses this method. matrowerks codewarrior uses any text pipeline as the precompile header source, this text includes frequently used and rarely changed headers, and then uses:
# Pragma precompile_target filename. PCH
Indicates the product that was created first, and then the. PCH specification must be used in codewarrior IDE.
(2)
As for VC settings, I don't know which version of VC you are using. net) for example, you can set "Create/use precompiled headers" to use precompiled headers on the [C/C ++ precompiled headers] Page, "Create/use PCH through file" is set to stdafx. H (VC Project template is just like this). Then, in the "precompiled header file" parameter, you can set the product (. PCH ).
(3)
You can include the commonly used <iostream> to stdafx. h, but remember to leave a blank line at the end. The CPP sequence that uses iostream does not understand include <iostream>.
# Include "stdafx. H" is used to find stdafx. H files in the current directory.
Change
# Include <stdafx. h> is used to find the stdafx. h file in the directory specified by VC.
(Method of Taiwan cell... by:-tie Gu)
Bytes -------------------------------------------------------------------------------------------
Cannot open include file: 'stdafx. H': no such file or directory error executing cl.exe.
I tray change project <Settings <C/C ++ <precompiled headers and it do not success.
Thank you
---------------------
Hi,
Cocould you please try doing "rebuild all" in build menu.
---------------------
You must save all files in the same folder
And
Use the same name of the header file as followes:
Sum. h // when you named your header file and saved it,
We must call it:
# Include "sum. H" in the. cpp file and Main. cpp
(For foreigners)
---------------------------------------------
Appendix:
1. Fatal error c1010: unexpected end of file while looking for precompiled header directive.
When searching for the pre-compiled header file path, the end of the file should not be encountered. (Generally no # include "stdafx. H ")
2. Fatal error c1083: cannot open include file: 'r ....... H': no such file or directory
You cannot open the file "r ....... H ": there is no such file or directory.
3. Error c2011: 'C ...... ': 'Class' type redefinition
Class "C ......" Redefinition.
4. Error c2018: unknown character '0xa3'
Unknown character '0xa3 '. (Generally Chinese characters or Chinese Punctuation Marks)
5. Error c2057: Expected constant expression
It is expected to be a constant expression. (Usually in the case Branch of the switch statement)
6. Error c2065: 'idd _ mydialog ': Undeclared identifier
"Idd_mydialog": Undeclared identifier.
7. Error c2082: redefinition of formal parameter 'breset'
The function parameter "breset" is redefined in the function body.
8. Error c2143: syntax error: Missing ': 'before '{'
Syntax error: ";" is missing before "{".
9. Error c2146: syntax error: Missing '; 'before identifier' DC'
Syntax error: ";" is lost before "DC".
10. Error c2196: Case value '69' already used
The Value 69 has been used. (Usually in the case Branch of the switch statement)
11. Error c2509: 'ontimer': member function not declared in 'chelloview'
The member function "ontimer" is not declared in "chelloview.
12. Error c2511: 'reset': overloaded member function 'void (INT) 'not found in' B'
The overloaded function "Void reset (INT)" cannot be found in class "B.
13. Error c2555: 'B: f1': overriding virtual function differs from 'A: f1' only by return type or calling convention
Class B's heavy load on function F1 of the same name in Class A is only based on the difference in the return value or call conventions.
14. Error c2660: 'settimer': function does not take 2 parameters
The "settimer" function does not pass two parameters.
15. Warning c4035: 'f ...... ': No Return Value
"F ......" The return statement does not return values.
16. Warning c4553: '=': operator has no effect; did you intend '= '?
The operator "=" with no effect; is it changed to "= "?
17. Warning c4700: local variable 'breset' used without having been initialized
The local variable "breset" is used without initialization.
18. Error c4716: 'cmyapp: initinstance': must return a value
The "cmyapp: initinstance" function must return a value.
19. Link: Fatal error lnk1168: cannot open debug/p1.exe for writing
Connection error: Unable to open the p1.exe file to rewrite the content. (P1.exe is still running, not closed)
20. Error lnk2001: unresolved external symbol "public: Virtual _ thiscall C ...... ::~ C ...... (Void )"
External symbols (variables, functions, etc.) that are not implemented are found during connection ).
(20 most common errors)
---------------------------------------------------------------------------