我使用 CMake FetchContent 下载 nlohmann/json。但我的 clangd 下载后不扫描库。那么我应该如何配置我的 clangd 呢?
我的 CMakeLists.txt:
cmake_minimum_required(VERSION 3.11)
project(ExampleProject LANGUAGES CXX)
include(FetchContent)
FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz)
FetchContent_MakeAvailable(json)
add_executable(example main.cc)
target_link_libraries(example PRIVATE nlohmann_json::nlohmann_json)
Run Code Online (Sandbox Code Playgroud)
和我的代码 main.cc:
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
json object = { { "one", 1 }, { "two", 2 } };
std::cout << object << '\n';
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我的 cland 说:
main.cc|2 col 10-29 error| 'nlohmann/json.hpp' file not found
main.cc|4 col 14-22 error| Use of undeclared identifier 'nlohmann' …Run Code Online (Sandbox Code Playgroud)