简介:nlohmann json是一个C++的JSON解析和生成库,非常方便。下面介绍其安装步骤。
nlohmann json是C++使用json的开源库,使用起来很方便。以下是安装方法:
你也可以手动下载源代码并解压到合适的文件夹下。
git clone https://github.com/nlohmann/json.git
然后使用cmake进行配置,并生成Makefile:
cd jsonmkdir buildcd build/
接下来,使用make命令编译代码:
cmake ..
最后,使用sudo make install命令安装nlohmann json:
make
sudo make install
然后添加需要链接的库和目标:
find_package(nlohmann_json 3.2.0 REQUIRED)
在上面的代码中,foo为可执行文件名称。
add_library(foo ...)target_link_libraries(foo ...)
请注意,安装完成后,头文件通常位于/usr/local/include/nlohmann/目录下。
#include "nlohmann/json.hpp"