1

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++

Luca Kiebel
  • 9,790
  • 7
  • 29
  • 44
Niclas
  • 19
  • 1
  • 3
  • Welcome to Stack Overflow. Please read [the help pages](http://stackoverflow.com/help), take the SO [tour], read [ask], as well as [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). And if you need to improve your question with details, then please **[edit]** it instead of writing comments. – Some programmer dude Jan 30 '22 at 12:48
  • I do have the file and it does get included when compiling and running. The problem is that the intelisense breaks when using a pch – Niclas Jan 30 '22 at 13:05
  • 1
    Does this answer your question? [What is "pch.h" and why is it needed to be included as the first header file?](https://stackoverflow.com/questions/54121917/what-is-pch-h-and-why-is-it-needed-to-be-included-as-the-first-header-file) – Ulrich Eckhardt Jan 30 '22 at 13:17
  • 2
    Is your include folders list configured to contain the "src" subfolder? See Project Property Pages → Configuration Properties → C/C++ → General → Additional Include Directories. Otherwise, the `#include "pch.h"` will not find the file because the "src" subfolder won't be considered. Also, do not exclude the "pch.h" from your project (because that file is also part of the project). – heap underrun Jan 30 '22 at 13:45
  • I think this is likely an issue with IntelliSense and the VS cache. Plenty of details/info in the question. I just either ignore or disable that wretched tool. – Adrian Mole Jan 30 '22 at 16:07

0 Answers0