VS2005 the MFC precompiled header file comes from an earlier version of the compiler, or the precompiled header is C + + and uses it in C (or vice versa)

Source: Internet
Author: User

When a Visual C + + project has the precompiled header (precompiled header) feature enabled, you may receive a C1853 compiler error if the project has both a. C and. cpp source files mixed: 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 I T from C (or vice versa) (Fatal error C1853: "filename.pch" The precompiled header file comes from an earlier version of the compiler, or the precompiled header is C + + and uses it in C (or vice versa).)

This error occurs because when the. cpp and. c files are mixed in the project, the compiler takes a different approach to compiling them (mainly because the function declaration is handled differently) and therefore cannot share a precompiled header file. In VC + +, the default precompiled header file is for C + + (StdAfx.h and Stdafx.cpp), and of course you can create a precompiled header for C.

Interestingly, in the old version of VC + +, this error hint is very misleading: fatal error C1853: ' xxx.pch ' is not a precompiled header file created with this compiler. It often makes people feel confused. It should be said that in the new version of this hint is improved. However, on the Internet search, the problem is often recommended to the entire project to cancel the precompiled header settings. This is obviously not a good solution. For a larger project, using precompiled headers can greatly reduce the overall compilation time. Therefore, it is a better solution to keep the precompiled header settings. Search MSDN, for different scenarios, there are different solutions: I am using the method resolved Scenario 1: Applies to the vast majority of files that are. cpp or most files are. c.

In this case, it is more balanced to set a small number of different class files to not use precompiled headers, by right-clicking in FileView for the. C (or. cpp) file that you want to cancel the precompiled header for vc++6.0, select Settings, and on the right of the popup dialog box, select Category is precompiled headers, then set option to not using ... ; (for VS2005, in the Solution Explorer, right-click on the corresponding file point and select Properties, under the precompiled Headers key, set the not using ... Can. If you need to set up multiple files, you can press and hold the Ctrl key and then select the files and set the PS: explain the following click on the item click Properties and then select C + + precompiled header to create a header file without using the precompiled header file Scenario 2: More files affected, They are all set to prohibit precompiled header words will still make the overall project compile speed greatly reduced, not worth the candle.

Consider creating a dedicated precompiled header for this set of files.

In the very early version of VC + + (1.5 and previous versions) is supported in a single project to establish a precompiled header for. C and. cpp, but only a separate precompiled header is supported in later versions. In this case, we can build a new static library project in workspace (or solution), and add all the. c files independently to the project and compile them separately so that you can target the. C in the static link library. The file is created with a precompiled header. But to some extent, the code that needs to be isolated is logically part of the same module, so it is easy to maintain. However, from the design point of view, this requirement is generally satisfied, otherwise you should consider the overall design of the project: P finally do not forget to set the original project Dependencies (dependency) for the independent out of this static library project.

Here's how:

Click the menu command "project/Properties" to bring up the Project Properties dialog box, or in Solution view or Class View, right-click the project name, select "Properties", and the Project Properties dialog box, and in the active configuration of the popup dialog box, select "Configure Properties/linker/input/Additional dependencies", You can enter the Lib library file to be added, click "Apply" or "OK" button. If you want to add a Lib library file to all configurations, you can switch the active configuration to all configurations first. In the configuration Properties---connector---general, the directory name of the library in which it is located, preferably a folder in the project folder that is specifically placed in Lib.

http://blog.csdn.net/yanjiaye520/article/details/4679841

VS2005 the MFC precompiled header file comes from an earlier version of the compiler, or the precompiled header is C + + and uses it in C (or vice versa)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.