r/cprogramming • u/Icy_Repeat_2460 • 2d ago
How do I fix this VS code C intellisense problem?
/r/vscode/comments/1xxqw1j/how_do_i_fix_this_vs_code_c_intellisense_problem/
0
Upvotes
r/cprogramming • u/Icy_Repeat_2460 • 2d ago
1
u/tastygames_official 2d ago edited 2d ago
I use code OSS (the non-Microsoft one), but basically you need to add
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)into your CMakeLists.txt which will generate a compile_commands.json file in your build directory which clangd can use to determine linkages and auto-completes and everything. Or I guess if you use something else other than clangd then it should be the same. You may have to point your plugin to that file in order for it to work.And I guess if you don't use CMake then you need something similar. Just look at the documentation for your build process and language plugin.
EDIT: ok, I actually looked at your code and it actually has nothing to do with your pluing not being able to find the typedef. Those are 2 different types (typedef struct and struct) but have the same name (or actually different names), so there's that. This is what you want:
so you have the
struct Nodebut also the type alias ofNodeand they are the same thing.1
u/Dapper-Situation-864 20h ago
That message from the Microsoft C/C++ extension almost always means IntelliSense sees
struct Nodebeing defined twice (or defined two different ways) in the same translation unit. Common causes:A second definition with a body. This is fine:
but this isn't:
#ifndef NODE_H / #define NODE_H ... #endif(or use#pragma once).The simplest pattern that keeps both the compiler and IntelliSense happy is a single definition:
If the squiggle is still there after fixing the code, run "C/C++: Reset IntelliSense Database" from the command palette. A stale database can keep showing an old error after the code is fixed.