首页 > 解决方案 > VSCode clangd 扩展找不到头文件

问题描述

我当前的文件结构是:

├── common
│   └── example.cc
├── compile_commands.json
├── include
    └── common
        └── example.hh

example.hh: 留空

example.cc

#include "common/example.hh"

int main() {
    return 0;
}

compile_commands.json

[
    {
        "directory": "/home/user/project",
        "file": "/home/user/project/common/example.cc",
        "arguments": [
            "/usr/bin/clang++",
            "-I /home/user/project/include",
            "-o example",
            "/home/user/project/common/example.cc"
        ],
        "output": "example"
    }
]

打开example.cc时会报错:

'common/example.hh' file not found clang(pp_file_not_found)

我直接运行命令,它工作正常:

$ /usr/bin/clang++ -I /home/user/project/include -o example /home/user/project/common/example.cc

环境信息:

$ clang++ --version
clang version 10.0.0-4ubuntu1 
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

VS代码:1.47.3

vscode-clangd:0.1.7

标签: visual-studio-codeclangclang++clangd

解决方案


推荐阅读