I am trying to create a makefile (yes, oldfashioned I know) which will allow use of precompiled headers and I succeeded using MSVC.
What I am not successfull is do the same with Intel Compiler.
I have a rule which says:
stable.pch : stdafx.cpp stdafx.h
$(CC) (options) /Ycstdafx.h /Fpstable.pch stdafx.cpp
$(CC) can be icl.exe or cl.exe depending on macro definitions.
With CL (MSVC), stable.pch gets created and subsequently used in other rules with /Yu and /Fpstable.pch with no issues.
With ICL (Intel), if there is no stable.pchi but there is stable.pch I get:
Catastrophic error: cannot open precompiled header file "stable.pchi"
Note the added "i" at the end of filename extension.
If I delete stable.pch left from MSVC, then Intel Compiler creates stable.pchi.
To me this looks like a compiler bug -- ICL doesn't find stable.pchi but since there is stable.pch it fails to create its own .pchi file.
I am using Update 3 (latest).
I think I did not describe the problem very well, most likely because I did not understand it properly at the time.
What really happens is this -- I have stable.pch generated by MSVC. If I switch compiler to ICL, NMAKE will see stable.pch target as present and it will proceed with compilation trying to use the file as it is. Intel compiler will then emit the error I mentioned because it cannot find what it expects to find and that is stable.pchi in its own format. If I delete stable.pch, then the build will work. Another problem is that with Intel Compiler stable.pchi gets regenerated each time which defeats the purpose of creating it in the first place.
I am not sure what I might be doing wrong with Intel Compiler and I really don't see a good workaround for this problem at the moment except to force cleaning of pch files on compiler switch which is exactly what happens in the Visual Studi IDE when you switch compilers.
I think I found a solution to rebuilding of .pchi:
!IF "$(INTEL)" == "1"
PCH_EXT = pchi
PCH_EXT = pch
stable.$(PCH_EXT) : stdafx.cpp stdafx.h
It is important that NMAKE target has proper extension or it won't see the file. Also, when you name the file in compiling options, you must not add "i" to extension because Intel Compiler will add it too.
The difference in suffix for the pre-compiled header files is intentional. Microsoft creates .pch files and Intel creates .pchi files. The pch files contain representations of the internal data structures used by the compiler and thus they cannot be made compatible. Because they are not compatible we intentionally named them differently. This prevent users who are using both compilers from trying to use an incompatible file.
I was suspecting as much regarding pch files.
However, I take issue with the following behavior:
1. I specify exact name and extension for PCH file and compiler adds "i" to the extension. I always find such behavior problematic with software -- ignoring/overriding user input, it is not a good practice. When I set a parameter such as file name I have certain expectations and other things I am doing may depend on the software following my exact instructions.
2. When using makefile one has to be wary of this because if target in makefile is specified as .pch instead of .pchi build won't work.
In my opinion, compiler should have kept the same extension and upon seeing PCH file from MSVC it should have just overwritten the file with its own format.