Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7956 Discussions

Precompiled headers and Intel Compiler

levicki
Valued Contributor I
1,032 Views

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.

0 Kudos
7 Replies
SergeyKostrov
Valued Contributor II
1,032 Views
>>...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... Igor, What version ( update ) of Intel C++ compiler do you use? Even if I'm compiling sources with Visual Studio projects most of the time I did not have any significant issues with precompiled headers for a long time. Just in case, here are two command line options for two projects ( very similar in terms of configuration settings ). That is, a Microsoft set of options and Intel set of options: [ Microsoft C++ compiler - Win32 - Release ] /O2 /I "..\..\Include" /D "WIN32" /D "_CONSOLE" /D "NDEBUG" /D "_WIN32_MSC" /D "_UNICODE" /D "UNICODE" /GF /Gm /EHsc /MT /fp:fast /openmp /Yu"Stdphf.h" /Fp"Release\MscTestApp.pch" /Fo"Release/" /Fd"Release/" /W4 /nologo /c /Wp64 /Zi /TP /U "_WIN32CE_MSC" /U "WIN32_PLATFORM_PSPC" /U "WIN32_PLATFORM_WFSP" /U "WIN32_PLATFORM_WM50" /U "_WIN32_MGW" /U "_WIN32_BCC" /U "_COS16_TCC" /errorReport:prompt [ Intel C++ compiler - Win32 - Release ] /c /O2 /I "..\..\Include" /D "WIN32" /D "_CONSOLE" /D "NDEBUG" /D "_WIN32_ICC" /D "INTEL_SUITE_VERSION=PE121_300" /D "_VC80_UPGRADE=0x0710" /D "_UNICODE" /D "UNICODE" /GF /EHsc /MT /GS /fp:fast=2 /Yu"Stdphf.h" /Fp"Release\IccTestApp.pch" /Fo"Release/" /W5 /nologo /Wp64 /Zi /TP /U "_WIN32_MSC" /U "_WIN32CE_MSC" /U "WIN32_PLATFORM_PSPC" /U "WIN32_PLATFORM_WFSP" /U "WIN32_PLATFORM_WM50" /U "_WIN32_MGW" /U "_WIN32_BCC" /U "_COS16_TCC" /Qopenmp /Qdiag-disable:111,673
0 Kudos
levicki
Valued Contributor I
1,032 Views

Hello Sergey,

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.

0 Kudos
levicki
Valued Contributor I
1,032 Views

I think I found a solution to rebuilding of .pchi:

!IF "$(INTEL)" == "1"
PCH_EXT = pchi
!ELSE
PCH_EXT = pch
!ENDIF
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.

0 Kudos
SergeyKostrov
Valued Contributor II
1,032 Views
>>...Another problem is that with Intel Compiler stable.pchi gets regenerated each time which defeats the purpose of >>creating it in the first place... That is really odd for version 13.x. By the way, the same problem ( that is, pch is generated every time ) exists for version 8.x of Intel C++ compiler and it really increases compilation time ( ~5 mins vs. ~30 secs ).
0 Kudos
Judith_W_Intel
Employee
1,032 Views

 

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.

Judy

0 Kudos
levicki
Valued Contributor I
1,032 Views

Hello Judy,

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.

0 Kudos
SergeyKostrov
Valued Contributor II
1,032 Views
>>...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... This is so simple and I think an additional compiler option could solve that issue and Igor's proposal should be considered as a Feature Request. Igor, I've attached two files and I hope they will help you. So, older Visual C++ compilers allowed to export project settings to a Makefile. These files are from Visual C++ 6.0 Enterprise Edition ( SP5 ): IccTestApp.VS98EE.dsp.txt IccTestApp.VS98EE.mak.txt and take a look ( I added txt extension to upload ).
0 Kudos
Reply