【问题标题】:Compile Error: Cannot open precompiled header.pch -- No such file or directory编译错误:无法打开预编译的 header.pch -- 没有这样的文件或目录
【发布时间】:2016-01-14 20:53:31
【问题描述】:

我最近购买了 Bjarne Stroustrup 的“编程:使用 C++ 的原则和实践”一书,并一直在关注它。我目前被困在一个早期项目中,我需要输出一些文本字符串。在 Windows 10 Lenovo Yoga 2 Pro 笔记本电脑上使用 Visual Studio Community 2015 更新 1,我尝试编译该项目,但遇到了详细的错误:

“无法打开预编译的头文件:Debug\Finding the Upstairs Bathroom.pch':没有这样的文件或目录”。该项目的名称恰如其分地命名为“寻找楼上浴室.cpp”。代码如下:

// I have the headers "stdafx.h" as well as this specific header lib 
// Bjarne Stroustrup created and which I had linked
// called "../../std_lib_facilities.h", which contains the standard C++ lib functions.

(#) define _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS 1

int main()`// Main function`

{  
    cout << "Take the key out of your right pants pocket\n"; // Outputs string of text

    cout << "Unlock the front door of the house\n";

    cout << "Open the front door and step inside\n";

    cout << "Lock the front door using the key\n";

    cout << "Move up the stairs, taking them two at a time\n";

    cout << "Walk to the second door on the left and face it directly\n";

    cout << "Using the door handle, turn it and push the door forward\n";

    cout << "Enter the bathroom while leaving the door open behind you\n";

    keep_window_open();

    return 0;
}

如果有人能够弄清楚如何解决我的错误,我将不胜感激。

【问题讨论】:

  • 显示所有包含的内容
  • 我会关闭预编译的头文件,或者学习如何使用它们。 msdn.microsoft.com/en-us/library/b4w02hte.aspx
  • 我的包含是:#include #include #include #include #include #include #include #include #include #include
  • 另外,您似乎正在使用 MFC(有一段时间没有使用 VS,但我很确定是这种情况)。如果您想学习 C++,最好避免使用此类框架,而使用标准库。

标签: c++ compiler-errors visual-studio-2015


【解决方案1】:

有两种方法可以解决这个问题:

  • 重建整个项目。这应该(重新)创建预编译的头文件(或首先选择Build/Clean Solution)。

  • 关闭预编译头文件。 Project settings / C/C++ / Precompiled headers / Not Using Precompiled Headers.

【讨论】:

  • 我决定创建一个全新的项目并做同样的事情,但这次我没有预编译头文件。它编译成功。谢谢你的帮助。
  • @Rudis - 好的,但Build -&gt; Clean Solution 也应该适用于您的其他项目(然后完全重建)。
  • 如果有一天我遇到类似的错误,我会记住这一点
【解决方案2】:

根据 Danny_ds 提供的选项,您可以:

  • 创建预编译头文件:Project settings / C/C++ / Precompiled Headers

    Precompiled Headers: Create (/Yc)

  • 禁用预编译头文件。 Project settings / C/C++ / Precompiled Headers

    Precompiled Headers: Not Using Precompiled Headers

当我第一次必须创建预编译的标头时遇到了问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-14
    • 1970-01-01
    • 1970-01-01
    • 2016-05-21
    • 2012-04-24
    相关资源
    最近更新 更多