C++: cannot open source file "pch.h"

3.9k Views Asked by At

I'm using Visual Studio 2022, and trying to use precompiled headers. In my project settings under all configurations I have:

Precompiled Header:              Use (/Yu)
Precompiled Header File:         pch.h
Precompiled Header Output Fille: $(IntDir)$(TargetName).pch

In the properties of the pch.cpp file, I have the following settings:

Precompiled Header:             Create (/Yc)
Precompiled Header File:        pch.h
Precompiled Header Output File: $(IntDir)$TargetName).pch

My project compiles just fine, but I get a squiggly line under the #include "pch.h" in every file, except for main.cpp which is in the same directory as the pch.h file. I right-clicked the pch.h file and pressed Exclude from project but the problem persists.

If I remove the #include "pch.h" from the beginning of a file, I get a new error: Precompiled header must be included at the top of source file.

pch.cpp:

#include "pch.h"

pch.h:

#pragma once

[... std includes ...]

#include "Mineclone/Debug/Log.h"
#include "Mineclone/Debug/Assert.h"

My project structure

I am using C++20 and IntelliJ ReSharper C++

0

There are 0 best solutions below