yaml-cpp
以前一直以一种自定义的格式写自己程序的配置文件,非常不友好也不方便使用,最近正好想整理一下自己程序,打算使用yaml文件形式作为后续程序的配置文件,于是就上网找了下C++版本的yaml解析库,果然,开源大法好,找到了yaml-cpp,打算尝试一下。
我 的 测 试 环 境 是 W S L − U b u n t u 20.04 我的测试环境是 WSL-Ubuntu 20.04 我的测试环境是WSL−Ubuntu20.04
安装
我下载的是0.7.0 版本
mkdir yaml && cd yaml
wget https://codeload.github.com/jbeder/yaml-cpp/tar.gz/refs/tags/yaml-cpp-0.7.0
tar -zvxf yaml-cpp-0.7.0
yaml-cpp是使用cmake管理,因此十分方便,
cd yaml-cpp-yaml-cpp-0.7.0
mkdir build && cd build
cmake [-G generator] [-YAML_BUILD_SHARED_LIBS=on|OFF] ..
make -j4
sudo make install
The generator option is the build system you’d like to use. Run cmake without arguments to see a full list of available generators.
- On Windows, you might use “Visual Studio 12 2013” (VS 2013 32-bits), or “Visual Studio 14 2015 Win64” (VS 2015 64-bits).
- On OS X, you might use “Xcode”.
- On a UNIX-like system, omit the option (for a Makefile).
yaml-cpp builds a static library by default, you may want to build a shared library by specifying -YAML_BUILD_SHARED_LIBS=ON.
这样就安装完成了
使用
接下来新建一个C++工程来尝试使用: