场景
如果在我的VS项目中有以下目录结构。
project/
|
|-- include/
| |
| pch.h
|
|-- src/
| |
| pch.cpp
|
Project.cpp我的文件是这样写的:
Project.cpp
#include "include/pch.h"
int main()
{
std::cout << "Hello World!\n";
}pch.h
#ifndef _PCH_H
#define _PCH_H
// IO Libraries
#include <iostream>
#include <iomanip>
#include <io.h>
#include <ostream>
#include <conio.h>
... more headers
#endif // !_PCH_Hpch.cpp
#include "../include/pch.h"现在,每个元素的属性配置为预编译头,如下所示:
项目
Precompiled Header Use(/Yu)
Precompiled Header File pch.h
Precompiled Header Output File $(IntDir)$(TargetName).pchpch.cpp
Precompiled Header Create(/Yc)
Precompiled Header File pch.h
Precompiled Header Output File $(IntDir)$(TargetName).pch问题
当我试图编译这个项目时,我会收到以下错误:
Severity Code Description
-------------------------------------------------------------------------------------------------------
Error C2857 '#include' statement specified with the /Ycpch.h command-line option was not found in the source file
Project File Line
-------------------------------------------------------------------------------------------------------
C:\Workspace\VisualStudio\C++\Poker\Poker\src\pch.cpp 2发布于 2019-11-21 01:34:41
当在源文件上使用/Ycfilename选项创建预编译头文件时,该源文件必须包括文件名头文件。源文件包含的每个文件,包括指定的文件名,都包含在PCH文件中。在使用/Yufilename选项编译的其他源文件中,文件名的包含必须是文件中的第一个非注释行。编译器忽略源文件中的任何内容,然后才包括在内。
如果这些细节中的任何一个都是错误的,那么您就会遇到编译错误。在我看来,您为/Yc选择的源文件实际上并不包括"pch.h“。
https://stackoverflow.com/questions/58964711
复制相似问题