Repository navigation
Description
This issue was originally created at: 2005-07-14 16:04:41.
This issue was reported by: schooner.
schooner said at 2005-07-14 16:04:41
Consider the Sconstruct with the files associated with the build in the attached zip file. The build is specified with MSVS 7.1 (though the problem occurs even with MSVC 6.0). If you try to build, you will get the following output:
cl /nologo /TP -GX -Ox /c SourcePrecompC.c /FoSourcePrecompC.obj /YcSource.h /FpSourcePrecompC.pch SourcePrecompC.c
cl /nologo -GX -Ox /c Source2.c /FoSource2.obj /YuSource.h /FpSourcePrecompC.pch Source2.c
Source2.c(1) : fatal error C1853: 'SourcePrecompC.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 (or vice versa)
scons: *** [Source2.obj] Error 2
The important part to note is "the precompiled header is C++ and you are using it from C" - This happens because when SCons builds SourcePrecompC.c , it adds the /TP flag which instructs the compiler to build the file as a C++ file. However, this needs to be compiled as a c file so that it can be used as the precompiled header for Source2.c, which is a c source file.
The MSVC tool should figure out what flags to pass for the PCH just as it does when it is just a source file.
issues@scons said at 2005-07-14 16:04:41
Converted from SourceForge tracker item 1238542
gregnoel said at 2008-10-05 07:54:06
Bug party triage. Gary to research and see if it's still a problem.
garyo said at 2008-10-05 18:46:42
I'd like to look into this bug, but it seems like the attachment is missing. It might have been lost when we converted to Tigris. Schooner, if you're still around (I know this was a long time ago!) could you repost the attachment? If I don't hear anything in a week, I'll have to close the bug due to lack of ability to reproduce it.
garyo said at 2008-10-19 06:28:16
Resolving as invalid due to missing attachment & no reply from OP, sorry.
Activity
mwichmann commentedon Nov 5, 2023
This bug got closed for reproducibility reasons, but it's not hard to conclude the report hits on something significant. The compiler itself has reported a problem as:
Showing us they can't be mixed, and the current implementation (
SCons/Tool/msvc.py) sets the compiler for a PCH build unconditionally to:$CXXevaluates to the same as$CCso that's not a problem, but$CXXFLAGScontains/TP, which means C++, as noted in the original report. From the Microsoft docs:So we don't really have a mechanism in place to distinguish between C and C++, we just tell the compiler to assume it's all C++. Which usually isn't an issue, since C is part of the C++ standard, so they're essentially compatible, but in the case of PCH files, Microsoft has chosen to make a distinction.
Temporarily, I'm reopening this - it's possible the resolution is "tough, we're not going to go down this rathole, Don't Do That" (which might imply a small doc note somewhere).
mwichmann commentedon Nov 13, 2023
PR #4441 proposes wording to at least document this assumption ("PCH is always C++"). It's done as a note so easy to update if there's ever a resolution to this issue.