8

New install of VSCode. The only extension I have installed is the Microsoft C/C++ Intellisense plugin. Version 0.24.1

I'm working with a codebase that has some header files with #define X foo macros. In the .cpp files it underlines these in red and says "identifier X is undefined". However if I ctrl+click/F12 it takes me to the .h file(s) with the macro defined.

This is the only extension I have right now so I don't think it's an issue of plugins competing. It seems common to macros with multiple definitions. i.e. we have

chipset1/include/registers.h and

chipset2/include/registers.h

which might both #define REG1 0xF00 or similar. However I only have "${workspaceFolder}/chipset1/include" in my .vscode/c_cpp_properties.json file. So I don't know why it's searching the chipset2 definitions as well. Perhaps this is causing the issue and the error message is misleading and should really say something like "multiple definitions found"? Still unsure why this behavior is occurring.

0

4 Answers 4

1

I had a similar problem after I switched the version of c++ to 20, but my c_cpp_properties.json was still set up for c++17.

I had set tasks.json as

"args": [
            ...,
            "-std=c++20"
        ],

The problem was fixed after I set (I was using the mingw compiler, not MS) in c_cpp_properties.json

"cppStandard": "gnu++20",
1
  • This was the problem for me, I had to go into C++ intellisense settings in VSCode and change the standard to c++20
    – Gillespie
    Commented Feb 24 at 18:27
0

Intellisense works by running a compiler on the code, while the click-through resolutions seem to use the includePath specified in .vscode/c_cpp_properties.json. You are likely missing #include registers.h in your source code file. Since registers.h is on your includePath, the click-through still works.

You can test this by compiling your code and seeing if it tells you you have undefined references.

As for your multiple references issue, I would double check which one is actually being included in your source code on the #include lines.

0

In my case, I solved the problem by adding

"compilerArgs":["-DXXX"],

those XXX are defines that are missing. compilerArgs tag resides in the file c_cpp_properties.json under .vscode folder.

check: https://code.visualstudio.com/docs/cpp/c-cpp-properties-schema-reference

-1

Replace this line in c_cpp_properties.json: "configurationProvider": "ms-vscode.cmake-tools"

With: "configurationProvider": "ms-vscode.cpptools-tools"

1
  • 4
    Why? What does this do?
    – Qwertie
    Commented Jan 14, 2023 at 6:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.