为什么在创建预编译头时也创建了对象?

发布于 2024-11-15 03:37:52 字数 584 浏览 3 评论 0原文

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

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

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

我在网上搜索后,在msdn上找到了一个教程: http://msdn.microsoft.com/en-我们/library/d9b6wk21(v=VS.71).aspx 我无法理解一行:

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

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

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

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

Bonjour°[大白 2024-11-22 03:37:52

由于您尝试在 makefile 中执行此操作,因此我会尝试遵循该教程中建议的模式(MSDN 中一直到 VS2010 都是相同的)。这就是 Microsoft 希望您在 makefile 中处理 PCH 生成的方式,是吗?

您这样做的方式并没有给您正确的结果 - 您不应该看到 PCH 的 OBJ 文件。让你的 makefile 与 Microsoft 模型相匹配,也许你会没事的。

关于需要在 makefile 的命令行中对文件进行编码以进行 PCH 编译 - 该教程的其他地方有更多的基本原理 这里

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.

眼眸里的快感 2024-11-22 03:37:52

MSDN 至少在 其他 2 地点

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文