2

我想在 make 文件中创建一个 .pch 。cl /nologo /c /YcPrecompiled.hpp /FpPrecompiled.pch Precompiled.cpp

让我感到困惑的是:为什么这个命令还创建一个名为 Precompiled.obj 的对象

我应该将此对象链接到结局 exe 吗?

在网上搜索后,我找到了一个关于msdn的教程:http: //msdn.microsoft.com/en-us/library/d9b6wk21 (v=VS.71).aspx 一行我看不懂:

$(CPP) $(CLFLAGS) /Yc$(BOUNDRY)    applib.cpp myapp.cpp

创建pch时,为什么需要applib.cpp和myapp.cpp。它还创建了两个对象,applib.obj,myapp.obj,除了 .pch 文件......为什么?

欢迎任何指示。非常感谢!

4

2 回答 2

0

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.

于 2011-06-10T19:43:47.283 回答
0

MSDN 至少在其他两个地方确实提到了它:

STDAFX.CPP、STDAFX.H:这些文件用于构建预编译的头文件 PROJNAME.PCH 和预编译的类型文件 STDAFX.OBJ。

这个描述确实没有清楚地区分预编译头和预编译类型。在 MFC 项目中的典型 stdafx.obj 上运行dumpbin,您会看到它包含一大堆静态ATL 类型,其定义隐藏在包含树的某个深处:

     ...
     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)
     ...

哪种有意义 - 如果您在 pch 中定义一个静态变量,则没有其他合理的地方可以放入它。

于 2014-11-05T10:58:54.330 回答