Hi!I encountered a problem when using vscode and clangd to read code in the WSL environment: c.h references a.h and b.h sequentially, but b.h does not reference a.h. When b.h uses a variable declared in a.h, clangd will report an error(“Use of undeclared identifier ‘someVariable’ (fix available)clang(undeclared_var_use)”).But the compilation can be passed .How can this be resolved?
#pragma once
#ifndef A_H
#define A_H
extern int someVariable;
#endif // A_H
#pragma once
#ifndef B_H
#define B_H
void someFunction() {
someVariable = 42;
}
#endif // B_H
#include "a.h" // 显式包含 a.h 以确保 someVariable 的声明可见
#include "b.h"
#include <stdio.h>
#include "c.h"
int someVariable = 0;
int main() {
someFunction();
printf("someVariable is now: %d\n", someVariable);
return 0;
}