4
votes

I am on macOS 10.15, I am using vscode for a project. For this project, I set up precompiled headers. The compilation works well, but the precompiled headers are not included in my files. Instead, they are included with the compiler option -include pch.hpp (as stated here ). The problem is that because I have not those includes in my file, IntelliSense is not working well and I have a lot of include error. In the c_cpp_properties.json I tried to add the line

"compilerArgs": [
"-include ${workspaceFolder}/emulator/pch.hpp"
]

but it didn't work, the errors are still here. Is there a way to tell IntelliSense to automatically include a file ?

What I did before was to have

#ifndef BUILD
   #include "pch.hpp"
#endif

in a util.hpp file included in all my other files and to define BUILD with -DBUILD when compiling. The problem is that whenever I modify my util.hpp file I have to recreate my precompiled headers file because I had an error from clang telling me that my util.hpp file was newer than the precompiled header.

1

1 Answers

2
votes

Use forcedInclude, c_cpp_properties.json:

"configurations": [
    {
       ...
       "forcedInclude": ["${workspaceFolder}/include/config.h"],
       ...
    }
]