I'm looking at adding pre-compiled headers to our scons project. I followed this post http://chadaustin.me/2009/05/unintrusive-precompiled-headers-pch/ and came up with
if ARGUMENTS.get('PRECOMPILED', 'FALSE') == 'TRUE':
PCH, PCH_OBJ = env.PCH('precompiled.cpp')
env['PCH'] = PCH
env['PCHSTOP'] = 'precompiled.h'
env.Append(CPPFLAGS=['/FI' + 'precompiled.h'])
The '/FI' means I don't need to manually add precompiled.h to each .cpp file.
But... I'm getting a warning for each .obj file
warning LNK4206: precompiled type information not found;
'xxx.obj' not linked or overwritten; linking object as if no debug info
which I can't seem to figure out.
I'm not clear on the Microsoft documentation for this warning. http://msdn.microsoft.com/en-us/library/cf1aswwe.aspx
The given object file, compiled with /Yc, was either not specified in the LINK command or was overwritten.
How would I resolve this?
A common scenario for this warning is when the .obj that was compiled with /Yc is in a library, and where there are no symbol references to that .obj from your code. In that case, the linker will not use (or even see) the .obj file. In this situation, you should recompile your code and use /Yl for the remaining objects (the objects that are not compiled with /Yc).
I don't think this is my problem but maybe?
scons run the following command line to create the pdb
i.e. env['PCHCOM']
'$CXX /Fo${TARGETS[1]} $CXXFLAGS $CCFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS /c $SOURCES /Yc$PCHSTOP /Fp${TARGETS[0]} $CCPDBFLAGS $PCHPDBFLAGS'
Which expands to i.e. env.subst(env['PCHCOM'])
'cl /Fo /TP /EHsc /nologo /errorReport:prompt /W3 /EHsc /Z7 /MD /O2 /FIprecompiled.h /DNDEBUG /D_UNICODE /DUNICODE /DWIN32 /DCSFUNIFIED_EXPORTS /DUNIFIED_DLL /IC /I: /I\ /ID /Ie /Iv /Ie /Il /Io /Ip /Im /Ie /In /It /I\ /Is /Iy /Is /It /Ie /Im /Is /Ie /Ir /Iv /Ii /Ic /Ie /I\ /Id /Ie /Ip /Ie /In /Id /Ie /In /Ic /Ii /Ie /Is /I\ /Ip /Ir /Ie /Ic /Io /Im /Ip /Ii /Il /Ie /Id /c /Ycprecompiled.h /Fp'
Update
Adding information requested by GaryO
Note I've since updated the code to
if ARGUMENTS.get('PRECOMPILED', 'FALSE') == 'TRUE':
PCH, PCH_OBJ = env.PCH('precompiled.cpp')
env['PCH'] = PCH
env['PCHSTOP'] = 'precompiled.h'
env.Append(CPPFLAGS=['/FI' + 'precompiled.h'])
env.Append(LIBS = PCH_OBJ)
in an attempt to resolve the warning.
The command to create the pre-compiled header
cl /Fodependencies\precompiled\precompiled.obj /TP /EHsc /nologo /errorReport:prompt /W3 /EHsc /Z7 /MD /O2 /FIprecompiled.h /DNDEBUG /D_UNICODE /DUNICODE /DWIN32 /Idependencies\precompiled /c dependencies\precompiled\precompiled.cpp /Ycprecompiled.h /Fpdependencies\precompiled\precompiled.pch
Here is the link command
link /nologo /DEBUG /OPT:REF /OPT:ICF /DEBUG /dll /out:out\windows-x86-MD-unicode-vs2008-rel\bin\csflogger.dll /implib:out\windows-x86-MD-unicode-vs2008-rel\bin\csflogger.lib dependencies\precompiled\precompiled.obj out\windows-x86-MD-unicode-vs2008-rel\bin\apr-1.lib out\windows-x86-MD-unicode-vs2008-rel\bin\aprutil-1.lib out\windows-x86-MD-unicode-vs2008-rel\bin\log4cxx.lib ws2_32.lib DnsAPI.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib psapi.lib out\windows-x86-MD-unicode-vs2008-rel\obj-shared\dependencies\csflogger\src\main\CSFLog.obj out\windows-x86-MD-unicode-vs2008-rel\obj-shared\dependencies\csflogger\src\main\VersionInfo.obj out\windows-x86-MD-unicode-vs2008-rel\obj-shared\dependencies\csflogger\src\main\logger_utils.obj out\windows-x86-MD-unicode-vs2008-rel\obj-shared\dependencies\csflogger\src\main\CSFLogger.obj
On the initial build this does not produce a warning. However if I then modify the project (e.g. comment out a line in precomipled.h) I get the above warning. i.e. Even though the link command is the same.
By adding
env.Append(LIBS = PCH_OBJ)
I thought I was fixing the issue. i.e. Because the .obj should be found. This can be seen in the link command
dependencies\precompiled\precompiled.obj
But it does not fix anything :(.
For completeness here is the command used to compile with the pre-compiled header
cl /Foout\windows-x86-MD-unicode-vs2008-rel\obj-shared\src\framework\SystemServiceDependencyInjector.obj /c src\framework\SystemServiceDependencyInjector.cpp /TP /EHsc /nologo /errorReport:prompt /W3 /EHsc /Z7 /MD /O2 /FIprecompiled.h -W3 -WX /wd4250 /wd4251 /DNDEBUG /D_UNICODE /DUNICODE /DWIN32 /DCSFUNIFIED_EXPORTS /DUNIFIED_DLL /DUSE_TR1_SMART_PTR /DUSE_TR1_SMART_PTR /DWIN32 /DCSFUNIFIED_EXPORTS /DUNIFIED_DLL /Idependencies\precompiled /Iinclude /Iapi /Itestutils /Idependencies\boost /Idependencies\csf2g-foundation\include\portability /Idependencies\csf2g-foundation\include\deprecated /Idependencies\csf2g-foundation\include /Idependencies\csflogger\include /Idependencies\log4cxx\include /Idependencies\libxml2\include /Idependencies\libcurl\include /Idependencies\libcurl\windows\include /Idependencies\ciscossl\releaseTempCiscoSSLTopFolder\inc32 /Idependencies\csf2g-idm\include /Idependencies\jcfcoreutils\include /Idependencies\httpdownloader\include /Idependencies\servicesframework\include /Idependencies\servicesframework\api /Idependencies\configservice-api /Idependencies\csf2g-foundation\include\dnsutils /Idependencies\csf2g-uc-service-locator\include /Idependencies\ucm9-config\include /Idependencies\ucm9-config\src /Idependencies\ucm9-config\src\dns /Idependencies\configservice\include /Idependencies\configservice\api /Idependencies\csfnetutils\include /Yuprecompiled.h "/Fpdependencies\precompiled\precompiled.pch"
Again its the same for the scenario with & without the warning.