我现在在VSCode中用clangd.There编写C/C++是一些恼人的problems.For示例,我在"a.h“中定义了一个变量,它也使用在" b.h ".But中它将在B.H中出错:
“未知类型名称‘xxxxx’‘clang(Unknown_typename)”。
实际上,它并不影响复杂的结果,但总是有很多恼人的红波在那里。
//in "a.h"
typedef unsigned long uint64;
//in "b.h"
uint64 abc; //Error here: (Unknown type name 'uint64'clang(unknown_typename)
//in "xxx.c"
#include "a.h"
#include "b.h"
abc=1; // Correct here
我只使用"complile_commands.json“来配置clangd,运行良好的是,我可以轻松地跳到definition或declaration.Is那里,还有我需要配置的clangd吗?
(PS:这是我的房子)
"clangd.onConfigChanged": "restart",
"clangd.arguments": [
"--clang-tidy",
"--clang-tidy-checks=performance-*,bugprone-*",
"--compile-commands-dir=${workspaceFolder}/.vscode/",
"--background-index",
"--completion-style=detailed",
"--enable-config",
"--function-arg-placeholders=false",
"--all-scopes-completion",
"--header-insertion-decorators",
"--header-insertion=never",
"--log=verbose",
"--pch-storage=memory",
"--pretty",
"--ranking-model=decision_forest",
"--cross-file-rename",
"-j=16"
],
"clangd.checkUpdates": false,
发布于 2022-08-07 08:41:15
这与VScode或clangd无关。
相反,问题是文件b.h
中没有包含a.h
,因此uint64
在您使用它的地方是未知的-- uint64 abc;
。
要解决这个问题,您需要在使用a.h
之前包含uint64
a.h
#pragma once
typedef unsigned long uint64;
b.h
#pragma once
#include "a.h" //added this
uint64 abc; //works now
https://stackoverflow.com/questions/73265936
复制相似问题