c++ - 预编译头 .pch 文件对机器敏感吗?

标签 c++ build visual-c++ precompiled-headers

我尝试通过以下方式重用 .pch 来加速构建:

  1. 在 stdafx.cpp 上使用/Yc 将 .pch 文件创建到文件夹
  2. 排除项目中的stdafx.cpp,并修改链接选项

它在我的机器上成功,但在另一台机器上失败,得到错误信息:error C2011: '***' : 'struct' type redefinition

所以首先我想问一下.pch 文件是否是机器敏感的?那么其次,以上方法可行吗?

谢谢!

最佳答案

预编译 header 可以是特定于 Visual Studio 2008 SP1 的机器(来自 here):

Precompiled header files store the “state” of a compilation up to a certain point, and that state information can be reused in subsequent compiler invocations to significantly increase build throughput. For the past 15 years, our compiler has persisted precompiled headers to disk and reloaded them directly into virtual memory with 99.999% reliability and considerable performance gains. The tradeoff, however, was a degree of fragility in our architecture.

Since the PCH file itself contains internal pointers, it must be loaded at the exact same address in virtual memory where it was created.

关于c++ - 预编译头 .pch 文件对机器敏感吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2597996/

相关文章:

c# - 如何在 TFS 自定义构建事件中获取构建项目

visual-c++ - OpenCV和包含文件

c++ - 空基优化 MSVC

c++ - 在 sqlite3 语句中绑定(bind) 'unsigned long' (uint64)? C++

c - 如何在没有 sudo 的情况下构建 Mongodb C 驱动程序

c++ - 广度优先或深度优先搜索

java - 无法找到 tools.jar

visual-c++ - WinRT-Windows应用商店-WinRT原始错误-如何解密此类错误?

python - 从 C++ 调用 Python 函数

java - 任何人都可以量化 C++ 和 Java 之间的性能差异吗?