Visual Studio 2015 中的预编译 header 错误

Precompiled header error in Visual Studio 2015

如果这个问题已经得到回答,请原谅,但我一直在尝试在我的游戏引擎中实现预编译的 headers,但到目前为止没有成功。

我的预编译header调用UtilBase.h:

#pragma once

#if !defined(NF3D_UTIL_BASE_H)
#define NF3D_UTIL_BASE_H

// This is a precompiled header.
#pragma message("Compiling precompiled header.")

// Include engine specific files.
#include <Utilities\Platform\Types.h>

// Include external header files (STL, Win32 API, Direct3D 11, etc)

// There are some typedefs here:  
typedef __int32 int32; // And so on.

#endif

尽管这违反了标准,但我在其他 header 中包含了 UtilBase.h,因为我需要访问其中的一些内容。它也包含在所有 .cpp 文件中,第一行,来自当前项目(该解决方案有两个项目)。

我在某些 header 中需要它,因为它存储了一些在函数声明中使用的 typedef。例如,我有一些名为 Window.h:

的文件
#pragma once // And include guards that are omitted here
int32 NF3DCreateWindow();

关联的源文件名为UtilBase.cpp,只有一行代码:

#include <Utilities\UtilBase.h>

我认为项目设置正确:

适用于所有平台和配置。

UtilBase.cpp 有这个设置:

但是,当我编译时出现这个错误:

1>Source Files\Utilities\UtilBase.cpp(2): error C2857: '#include' statement specified with the /YcD:\New Frontiers\NewFrontiers3D\Header Files\Utilities\UtilBase.h command-line option was not found in the source file

它指向 UtilBase.cpp (#include <Utilities\UtilBase.h>) 中唯一的一行。

为什么会发生这种情况,我该怎么做才能让它发挥作用?我很乐意发送有关此情况的任何进一步信息。非常感谢您。

尝试#ifndef 而不是#if !defined

终于成功了!对于处于我这种情况的任何人,我都这样做了:在项目设置中,Precompiled Header File 标记中,我添加了 $(ProjDir)\Header Files\Utilities\UtilBase.h 并将其评估为文件的完整路径。正确的方法是简单地添加文件:Utilities\UtilBase.h 就是这样。

感谢您的支持。