PRB: C1853 Error Generated by Mixing C and C++ Files (126717)
The information in this article applies to:
- Microsoft Visual C++, 32-bit Editions 2.0
- Microsoft Visual C++, 32-bit Editions 2.1
- Microsoft Visual C++, 32-bit Editions 4.0
- Microsoft Visual C++, 32-bit Enterprise Edition 5.0
- Microsoft Visual C++, 32-bit Professional Edition 5.0
- Microsoft Visual C++, 32-bit Enterprise Edition 6.0
- Microsoft Visual C++, 32-bit Professional Edition 6.0
- Microsoft Visual C++, 32-bit Learning Edition 6.0
This article was previously published under Q126717 SYMPTOMS
When you build Visual C++ projects that include both C and C++ files and
that use precompiled headers, you may receive the following error message:
fatal error C1853: '<filename>' is not a precompiled header file
created with this compiler
CAUSE
The compiler attempts to use a precompiled header generated by a C++
compiler on a C source file. This can happen when "Per-File Use of
Precompiled Headers" is used with both C and C++ source code in a project.
It is not valid to use a C++ compiler created precompiled header with a
source file that is to be compiled by the C compiler. Nor is it valid to
use a C compiler created precompiled header with a source file that is to
be compiled by the C++ compiler.
The Visual C++ version 2.x error message help for C1853 may be misleading.
It implies that the problem occurs only when mixing .PCH files
generated with the 16-bit and 32-bit compilers. Frequently, however, this
can occur when building a project after adding a C source file to a pure
C++ project that uses the "Per-File Use of Precompiled Headers." (The
Visual C++ version 4.0 online help correctly incorporates this information
by stating that fatal error C1853 "can be caused by using a precompiled
C++ file with C code.")
RESOLUTION
This problem can be resolved in several ways depending on the situation:
Resolution I
For projects with a single C source file and multiple C++ source files (or
vice-versa), use the following steps to disable precompiled headers for the
single source file: - For the current target, open the Project Settings dialog box and select
the Precompiled Headers section under the C/C++ Tab.
- Select the C file from the project tree in the left pane.
- For Visual C++ version 2.x, disable the Use .PCH File checkbox in the
Per-File Use of Precompiled Headers. For Visual C++ version 4.0, 5.0, and 6.0, select
the Not using precompiled headers option button.
- Save the new settings and build the project.
Resolution II
For projects with multiple C and C++ source files, use the following steps
to disable precompiled headers for a set of source files procedure: With Visual C++ version 2.x: - For the current target, create a New Group by choosing New Group from
the Project menu item.
- Move the C source files into the new group.
- Open the Project Settings and select the Precompiled Headers section
under the C/C++ tab dialog.
- Select the new group from the project tree in the left pane.
- Disable the Use .PCH File checkbox in the Per-File Use of Precompiled
Headers.
- Save the new settings and build the project.
This will disable precompiled headers for a set of source files. However,
source files in subsequent additions to this group may need the PCH usage
disabled depending on the file's previous settings. With Visual C++ version 4.0, groups are no longer supported. To disable
the use of precompiled headers for a group of source files, follow the
the steps of Resolution I, but in step 2 hold down the CRTL key while
selecting each file. Resolution III
For projects not requiring precompiled headers, follow the steps of
Resolution I, but in step 2 select all targets from the project tree in
the left pane.
Resolution IV (VC 4.x and 5.0)- Create a subproject of type "Static Library".
- Insert the .C files into this subproject.
- Delete the .C files from the top-level project.
- Add the resulting library or .obj files to the link line for the
top-level project.
This will allow you to specify a pre-compiled header for the top-level
project (.CPP files), and a different pre-compiled header for the
subproject (.C files).
STATUS
This behavior is by design.
REFERENCES
For more information on precompiled headers, please search on "Precompiled
Headers" in Books Online.
Modification Type: | Minor | Last Reviewed: | 7/5/2005 |
---|
Keywords: | kbCompiler kbCPPonly kberrmsg kbprb KB126717 |
---|
|