Transferred from: bytes]
When the precompiled header feature is enabled for the Visual C ++ project. C and. CPP source file, you may receive the c1853 compiler error: Fatal error c1853: 'pjtname. PCH 'precompiled header file is from a previous version of the compiler, or the precompiled header is C ++ and you are using it from C (orvice versa) (fatal error c1853: "filename. the PCH pre-compiled header file comes from an earlier version of the compiler, or the pre-compiled header is C ++ and is used in C (or vice versa )).
This error occurs because the project is mixed. CPP and. c files, the compiler will adopt different compilation methods for them (mainly because the processing methods for function declaration are different), and thus cannot share a precompiled header file. In VC ++, the default pre-compiled header file is for C ++ (stdafx. h and stdafx. cpp). Of course, you can also create a pre-compiled header for C. Interestingly, in earlier versions of VC ++, the error message is misleading: Fatal error c1853: 'xxx. pch' is not a precompiled header file created with this compiler. it is often confusing. It should be said that this prompt in the new version has been improved. However, when searching online, we recommend that you cancel the pre-compilation header settings for the entire project. This is obviously not a good solution. For a large project, the use of the pre-compilation header can greatly reduce the total Compilation Time. Therefore, it is better to retain the pre-compiled header settings. Search for msdn. There are different solutions for different situations:
I used method 1 to solve the problem.
Solution 1: applicable to the case where the vast majority of files are. cpp or the vast majority of files are. C. In this case, it is more balanced to set a few different types of files to not use the pre-compiled header by: for VC ++ 6.0, in FileView. C (or. CPP) Right-click the file and select Settings. In the displayed dialog box, set category to precompiled headers, and set the option not using ...; (For vs2005, right-click the corresponding file in Solution Explorer and select properties. In the precompiled headers field, set not using... you can. If you need to set multiple files, you can press and hold the ctrl key and then select these files and set) PS: click properties in the project and select the C/C ++ pre-compilation header to create a header file. Do not use the pre-compilation header file (solution Resource Manager-right-click the C or CPP file to be excluded). -Pop Up the properties menu-expand C/C ++-Pre-compilation headers-create/use pre-compilation headers-select not applicable pre-compilation headers)
Solution 2: if there are many files affected, setting all of them to disable the pre-compilation headers will greatly reduce the overall compilation speed of the project. In this case, you can create a special pre-compilation header for this set of files. In the early versions of VC ++ (1.5 and earlier versions), It is supported to create a separate target for a single project. C and. CPP pre-compilation header, but later versions only support separate pre-compilation headers. In this case, we can create a new static library project in the workspace (or solution). c files are independently added to the project for separate compilation, so that they can be targeted in the static Link Library. create a pre-compiled header in the C file. However, to a certain extent, the Code independently belongs to the same module logically to facilitate maintenance. However, from the design perspective, this requirement is generally met. Otherwise, we should consider the overall design of the project: P. Finally, don't forget to set the dependency of the original project) is a separate static library project.
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/shellching/archive/2010/01/27/5260590.aspx