Tag Archives: .c file

Fatal error C1853 error occurs when there are mixed .c files in the VS project

Fatal error C1853 appears in VS project with.c file mixed in
The CPP files in the project after the C file and an error occurs at compile time fatal error C1853: “the debug/1 _1. PCH” is not a precomplied header file with this complier…
Reason for error: This error is because when the.cpP and.c files are mixed in the project, the compiler compiles them differently (mainly because of the way it handles function declarations) and cannot share the same precompiled header file.
In VC++, the default precompiled header is for C++ (stdafx.h and stdafx.cpp), but it is also possible to create precompiled headers for C. Interestingly, in older versions of VC++, the error message was misleading: fatal error C1853: ‘XXX. PCH’ is not a precompiled header file created with this compiler. It’s often confusing. It should be said that this tip in the new edition is an improvement. However, a search of the Internet on this issue is often recommended for the entire project to remove the precompiled header setting. This is clearly not a good solution. For a large project, using precompiled headers can significantly reduce the total compile time. Therefore, it is a better solution to leave the precompiled header Settings. Search MSDN, for different situations, there can be different solutions:
Plan 1
This applies if the vast majority of files are.cpP or.c.
In this case, it would be more balanced to set a few files of different classes to not use precompiled headers by:
For VC++6.0, right-click the.c (or.cpp) file in the FileView to uncompile, select Settings, and on the right side of the dialog box, select category as precompiled headers, and set the option not using… ;
For VS2005, right-click on the corresponding file in the Solution Explorer and select Properties, and set Not using… under preHeaders. Can.
If you need to set more than one file, hold down the Ctrl key and select both files and set.

Scheme 2
If you have a large number of files affected, disabling precompilation headers on all of them will still make the overall compilation speed of the project much slower than it would otherwise be. Consider creating a dedicated precompiled header for this set of files. In very early versions of VC++ (1.5 and before), it was possible to create precompiled headers for.c and.cpp in a single project, but later versions only supported separate precompiled headers. In this case, we can set up a new Static Library project in the workspace (or Solution), add all.c files to the project and compile them separately, so that we can create a precompiled header for.c files in the Static Library. But to do so requires that the code that is separated logically belongs to the same module in order to be maintainable. From a design point of view, however, this requirement is generally met; otherwise, consider the overall design of the project 😛 And finally, don’t forget to set the original project’s dependency as a separate static library project.