Search code examples
c++visual-studio-codeintellisensevscode-extensions

How to fix PCH warning: header stop cannot be in a linkage block vscode


In vscode, after creating a c++ project from a template then removing all the template code and replacing with my own, I ran into the error PCH warning: header stop cannot be in a linkage block appearing as an error on one of my #include statements.

There are a few other SO focused on this topic, but many recommend changing code to include #pragma once or other such changes which modify the code itself. As this seems to be an intellisense issue, I want to know a fix to this that does not involve the code itself. This can be very bothersome as it seems to block other intellisense features.


Solution

  • It seems the best fix I could find is to turn off C_Cpp.intelliSenseCacheSize by setting it to 0 in your workspace settings json. I discovered this from this GitHub issue on the topic.

    Adding this line

    ...
    "settings": {
       "C_Cpp.intelliSenseCacheSize": 0,
    ...
    

    to your .code-workspace file seems to fix it. Might need to reload vscode to be safe.

    As far as why this helps, I think that (especially in cases where I was using a template to start) I think it has to do with this line from the GitHub issue:

    IntelliSense will auto generate precompiled headers (PCH) if there are any #include header files that it can cache.

    So it must be precompiling a header from the template that is removed and left hanging because it was the only header to begin with, or something like that. in 2019 there was a comment that this would likely be removed in a future version.