我应该如何配置clangd,使其扫描我使用CMake FetchContent下载的库
How should I configure clangd to make it scan the library I download with CMake FetchContent?
我使用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)
和我的代码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;
}
我的叮当声说:
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'
main.cc|8 col 5-9 error| Unknown type name 'json'
现在我知道如何解决这个问题了。
使用CMake时,将CMAKE_EXPORT_COMPILE_COMMANDS
设置为1,以使CMake生成文件compile_commands.json
。Clangd将自动扫描此文件,并跟随它扫描第三方库。
相关文章:
- 如何创建一个CMake变量,除非显式重写,否则使用默认值
- 使用C++库在Android项目中修改gradle中的cmake参数,用于插入指令的测试
- CMake-按正确顺序将项目与C运行时对象文件链接
- 使用CMake创建QML插件
- cmake如何在fedora工作站中找到boost静态库包
- 使用CMake检测支持的C++标准
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 如何使用CMake编译.proto文件来生成.grpcp.pb.cc和.grpc.pb.h文件
- cmake在我的项目中所需的所有静态库都不成功
- 在CMakeLists.txt的安装功能中使用.cmake文件有什么用
- 无法链接 CMake 中的本地库
- libssh 的函数在构建 libssh 时无法在 Qt 和 cmake 错误中找到
- 如何在Ubuntu中使用cmake设置qt4
- 使用cmake从源代码构建MySQL连接器/C++失败(与以前的声明冲突)
- 为什么 cmake 许可证<>样式不包括?
- cmake更新缓存的变量
- 将--whole archive链接器选项与CMake和具有其他库依赖项的库一起使用
- 使外部项目可用于find_package CMake
- 我可以在我的 cmake 代码中手动使用 CMake 的 cpp 文件依赖项扫描程序吗?
- 可以与CMAKE-BUILD一起使用Clang静态分析仪(扫描构建)