Bre*_*man 5 c linux makefile language-server-protocol clangd
我在自定义位置安装了一个库,编译和链接工作正常,但 clangd 报告与自定义库相关的各种错误。
我的 Makefile 有以下标志:
CFLAGS += -I/usr/local/share/mylib
LDFLAGS += -lmylib -L/usr/local/lib/
...
<snip>
Run Code Online (Sandbox Code Playgroud)
但是,clangd 不知道如何查找头文件,因此我的编辑器显示如下错误,但没有帮助:
#include <mylibheader.h> 'mylibheader.h' file not found
mylib_type1_t foo unknown type name 'mylib_type1_t'
...
<snip>
Run Code Online (Sandbox Code Playgroud)
在互联网上搜索错误和关键字clangd
, clangd config
,clangd .clang-format
未能在 SO 或其他地方产生任何有用的东西(因此这个问题)。
问题是:
如何告诉 clangd 我的非标准标头在哪里,以便它不会显示虚假的“文件未找到”警告?
Bre*_*man 10
将编译标志添加到compile_flags.txt
(小项目)或为更复杂的项目生成compile_commands.json
。请参阅此处的说明。
示例:我的compile_flags.txt
包含:
-I/usr/local/share/mylib\n-lmylib\n-L/usr/local/lib/\n
Run Code Online (Sandbox Code Playgroud)\nman 1 clangd
给出了检查输出的有用提示
--check[=<string>] - Parse one file in isolation instead of acting as a language server. Useful to investigate/reproduce crashes or configu\xe2\x80\x90\n ration problems. With --check=<filename>, attempts to parse a particular file.\n
Run Code Online (Sandbox Code Playgroud)\n一些输出clangd --check=src/main.c
:
E[13:12:40.787] [pp_file_not_found] Line 10: \'mylibheader.h\' file not found\n\nE[13:12:40.820] [unknown_typename] Line 187: unknown type name \'mylib_type1_t\'\nE[13:12:40.820] [unknown_typename] Line 202: unknown type name \'mylib_type1_t\'\nE[13:12:40.820] [undeclared_var_use] Line 820: use of undeclared identifier \'mylib_type2_t\'\n...\n<snip>\n
Run Code Online (Sandbox Code Playgroud)\n添加pp_file_not_found
到我的搜索词让我发现了这个非常有用的问题*,其中有一条评论说:
\n\n看起来您没有设置compile_flags.txt或compilation_database.json。该文件告诉 clangd 在哪里可以找到包含文件,您可以查看项目设置指南以获取详细信息。
\n
编译后生成compile_commands.json
使用./scripts/clang-tools/gen_compile_commands.py
(使用.cmd文件)。