Why the object is created also , When creating precompiled header?
I want to create a .pch within a make 开发者_开发百科file. cl /nologo /c /YcPrecompiled.hpp /FpPrecompiled.pch Precompiled.cpp
What confused me is : Why this command also create a object named Precompiled.obj
Should I link this object to the finale exe?
After I search on the web, I found a tutorial on msdn: http://msdn.microsoft.com/en-us/library/d9b6wk21(v=VS.71).aspx I cann't understand one line:
$(CPP) $(CLFLAGS) /Yc$(BOUNDRY) applib.cpp myapp.cpp
When creating a pch, why does it need applib.cpp and myapp.cpp. And It also create two objects, applib.obj, myapp.obj, except the .pch file....Why?
Any indication is welcomed. Thanks very much!
Since you're trying to do this in a makefile, I would try following the pattern suggested in that tutorial (which is the same all the way up to VS2010 in MSDN). This is how Microsoft wishes you to handle PCH generation within makefiles, yes?
The way you are doing it is not giving you the right results - you should not see an OBJ file for the PCH. Make your makefile match the Microsoft model and maybe you will be OK.
Regarding the need to code files in the makefile's command line for PCH compilation - there is a bit more rationale elsewhere in that tutorial here.
MSDN does mention it at least in other 2 places:
STDAFX.CPP, STDAFX.H : These files are used to build a precompiled header file PROJNAME.PCH and a precompiled types file STDAFX.OBJ.
This description indeed doesn't clearly distinguish between precompiled header and precompiled types. Running dumpbin on a typical stdafx.obj from an MFC project, you'd see it contains a whole bunch of static ATL types, whose definition is buried somewhere deep in the include tree:
...
COMDAT; sym= "struct ATL::IAtlAutoThreadModule * ATL::_pAtlAutoThreadModule" (?_pAtlAutoThreadModule@ATL@@3PEAUIAtlAutoThreadModule@1@EA)
COMDAT; sym= "public: static int const ATL::AtlLimits<int>::_Min" (?_Min@?$AtlLimits@H@ATL@@2HB)
COMDAT; sym= "public: static int const ATL::AtlLimits<int>::_Max" (?_Max@?$AtlLimits@H@ATL@@2HB)
COMDAT; sym= "public: static unsigned int const ATL::AtlLimits<unsigned int>::_Min" (?_Min@?$AtlLimits@I@ATL@@2IB)
COMDAT; sym= "private: static int (__cdecl* ATL::CNoUIAssertHook::s_pfnPrevHook)(int,char *,int *)" (?s_pfnPrevHook@CNoUIAssertHook@ATL@@0P6AHHPEADPEAH@ZEA)
COMDAT; sym= "public: static bool ATL::CAtlBaseModule::m_bInitFailed" (?m_bInitFailed@CAtlBaseModule@ATL@@2_NA)
COMDAT; sym= "public: static unsigned short const ATL::CVarTypeInfo<char>::VT" (?VT@?$CVarTypeInfo@D@ATL@@2GB)
COMDAT; sym= "public: static char tagVARIANT::* ATL::CVarTypeInfo<char>::pmField" (?pmField@?$CVarTypeInfo@D@ATL@@2QEQtagVARIANT@@DEQ3@)
COMDAT; sym= "public: static unsigned short const ATL::CVarTypeInfo<unsigned char>::VT" (?VT@?$CVarTypeInfo@E@ATL@@2GB)
...
Which kind of makes sense - if you define a static variable in a pch, there's no other reasonable place to put it in.
精彩评论