【问题标题】:How to get Clangd working properly with VS Code on Windows如何让 Clangd 在 Windows 上与 VS Code 一起正常工作
【发布时间】:2019-10-19 23:04:48
【问题描述】:

我无法让 clangd 为任何外部标头(例如来自 SFML)提供自动完成功能。

我已经尝试在 Ubuntu VM 上执行相同的操作,并且一切正常。 compile_commands.json 也已移至项目根目录。

项目树现在看起来像这样:

.clangd
--index
----main.cpp.1B607D111B8CF0BE.idx

build
--CMakeFiles etc

src
--main.cpp

CMakeLists.txt

compile_commands.json

CMakeLists.txt 包含以下内容:

cmake_minimum_required(VERSION 3.10)

project(test)

set(CMAKE_CXX_STANDARD 17)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(src_files
    src/main.cpp)

set(SFML_DIR "D:/Libs/SFML/SFML-2.5.1-windows-vc15-64-bit/SFML-2.5.1/lib/cmake/SFML/")

find_package(SFML COMPONENTS graphics)

add_executable(test ${src_files})

target_link_libraries(test PRIVATE sfml-graphics)

target_include_directories(test PRIVATE D:/Libs/SFML/SFML-2.5.1-windows-vc15-64-bit/SFML-2.5.1/include)

compile_commands.json 包含以下内容:

[
{
  "directory": "C:/Users/Joerg/projects/test/build",
  "command": "C:\\PROGRA~1\\LLVM\\bin\\CLANG_~1.EXE   @CMakeFiles/test.dir/includes_CXX.rsp -g -Xclang -gcodeview -O0 -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd   -std=gnu++17 -o CMakeFiles\\test.dir\\src\\main.cpp.obj -c C:\\Users\\Joerg\\projects\\test\\src\\main.cpp",
  "file": "C:/Users/Joerg/projects/test/src/main.cpp"
}
]

我也尝试过使用 MinGW Clang,其中对应的 compile_commands.json 如下所示:

[
{
  "directory": "C:/Users/Joerg/projects/test/build nin",
  "command": "C:\\msys64\\mingw64\\bin\\clang++.exe      -std=gnu++17 -o CMakeFiles\\test.dir\\src\\main.cpp.obj -c C:\\Users\\Joerg\\projects\\test\\src\\main.cpp",
  "file": "C:/Users/Joerg/projects/test/src/main.cpp"
}
]

我希望 clangd 为 SFML 命名空间 (sf::) 提供自动补全功能,就像它为 std 命名空间 (std::) 提供的一样。目前,当我写#include <SFML/Graphics.hpp> 时,它没有找到应有的标题。它给了我这个错误信息:'SFML/Graphics.hpp' file not found clang(pp_file_not_found)

【问题讨论】:

    标签: windows visual-studio-code clang clang++


    【解决方案1】:

    clangd 使用 compile_commands.json 获取包含属性,但是 10.0 以下的 clang 版本无法识别 .rsp 文件,例如 @CMakeFiles/test.dir/includes_CXX.rsp。这就是你的clangd找不到某些头文件的原因。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-08-18
      • 1970-01-01
      • 2019-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-24
      相关资源
      最近更新 更多