当前位置:   article > 正文

nlohmann json:安装_nlohmann安装

nlohmann安装

nlohmann json是C++使用json的开源库,使用起来很方便。

以下是安装方法:

1.在https://github.com/nlohmann/json.git clone代码。

2.在代码目录中创建目录build,即mkdir build

3.cd build

4.cmake ..

5.make

6.sudo make install

安装完成后可以通过引入头文件#include "nlohmann/json.hpp"来使用nlohmann json

而安装好的头文件通常位于:/usr/local/include/nlohmann/

注:我使用C++20的编译器会有编译报错,看起来是目前代码还不支持C++20的语法要求

可以进行如下几步修改CMakeLists.txt:

1.修改target_compile_features(${NLOHMANN_JSON_TARGET_NAME} INTERFACE cxx_std_11)为:

target_compile_features(${NLOHMANN_JSON_TARGET_NAME} INTERFACE cxx_std_20)

2.set(JSON_BuildTests_INIT ON)修改为set(JSON_BuildTests_INIT OFF)

这样修改后,将不会编译test目录下的程序,但是安装完成后,还是可以正常的使用nlohmann json编写程序

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/553869
推荐阅读
相关标签
  

闽ICP备14008679号