jbeder / yaml-cpp

jbeder / yaml-cpp

yaml-cpp is a YAML parser and emitter in C++ matching the YAML 1.2 spec. yaml-cpp 是一个符合 YAML 1.2 规范的 C++ YAML 解析器和生成器。

Usage

使用方法

See Tutorial and How to Emit YAML for reference. For the old API (until 0.5.0), see How To Parse A Document. 请参阅“教程”(Tutorial)和“如何生成 YAML”(How to Emit YAML)以获取参考。对于旧版 API(0.5.0 版本之前),请参阅“如何解析文档”(How To Parse A Document)。

How to Build

如何构建

yaml-cpp uses CMake to support cross-platform building. Install CMake (Resources -> Download) before proceeding. The basic steps to build are: yaml-cpp 使用 CMake 来支持跨平台构建。在继续之前,请先安装 CMake(资源 -> 下载)。基本的构建步骤如下:

Note: If you don’t use the provided installer for your platform, make sure that you add CMake’s bin folder to your path. 注意:如果您没有使用平台提供的安装程序,请确保将 CMake 的 bin 文件夹添加到您的系统路径(PATH)中。

  1. Navigate into the source directory, create build folder and run CMake:
  2. 进入源代码目录,创建 build 文件夹并运行 CMake:
mkdir build
cd build
cmake [-G generator] [-DYAML_BUILD_SHARED_LIBS=on|OFF] ..

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). generator 选项是您想要使用的构建系统。运行不带参数的 cmake 可以查看所有可用生成器的完整列表。在 Windows 上,您可以使用 “Visual Studio 12 2013” (VS 2013 32位) 或 “Visual Studio 14 2015 Win64” (VS 2015 64位)。在 OS X 上,您可以使用 “Xcode”。在类 UNIX 系统上,可以省略该选项(默认使用 Makefile)。

yaml-cpp builds a static library by default, you may want to build a shared library by specifying -DYAML_BUILD_SHARED_LIBS=ON. yaml-cpp 默认构建静态库,如果您希望构建动态库,可以指定 -DYAML_BUILD_SHARED_LIBS=ON。

Debug mode of the GNU standard C++ library can be used when both yaml-cpp and client code is compiled with the _GLIBCXX_DEBUG flag (e.g. by calling CMake with -D CMAKE_CXX_FLAGS_DEBUG=’-g -D_GLIBCXX_DEBUG’ option). Note that for yaml-cpp unit tests to run successfully, the GoogleTest library also must be built with this flag, i.e. the system one cannot be used (the YAML_USE_SYSTEM_GTEST CMake option must be OFF, which is the default). For more options on customizing the build, see the CMakeLists.txt file. 当 yaml-cpp 和客户端代码都使用 _GLIBCXX_DEBUG 标志编译时(例如通过调用带有 -D CMAKE_CXX_FLAGS_DEBUG=’-g -D_GLIBCXX_DEBUG’ 选项的 CMake),可以使用 GNU 标准 C++ 库的调试模式。请注意,为了使 yaml-cpp 单元测试成功运行,GoogleTest 库也必须使用此标志进行构建,即不能使用系统自带的库(CMake 选项 YAML_USE_SYSTEM_GTEST 必须为 OFF,这是默认设置)。有关自定义构建的更多选项,请参阅 CMakeLists.txt 文件。

  1. Build it! The command you’ll need to run depends on the generator you chose earlier. Note: To clean up, just remove the build directory.
  2. 构建!您需要运行的命令取决于您之前选择的生成器。注意:如需清理,只需删除 build 目录即可。

How to Integrate it within your project using CMake

如何使用 CMake 将其集成到您的项目中

You can use for example FetchContent: 例如,您可以使用 FetchContent:

include(FetchContent)
FetchContent_Declare(
  yaml-cpp
  GIT_REPOSITORY https://github.com/jbeder/yaml-cpp.git
  GIT_TAG <tag_name> # Can be a tag (yaml-cpp-x.x.x), a commit hash, or a branch name (master)
)
FetchContent_MakeAvailable(yaml-cpp)
target_link_libraries(YOUR_LIBRARY PUBLIC yaml-cpp::yaml-cpp) # The library or executable that require yaml-cpp library

Recent Releases

近期发布

yaml-cpp 0.9.0 released! yaml-cpp 0.3.0 is still available if you want the old API. The old API will stop receiving bugfixes in 2026. The 0.3.x versions provide the old API, and 0.5.x and above all provide the new API. yaml-cpp 0.9.0 已发布!如果您需要旧版 API,yaml-cpp 0.3.0 仍然可用。旧版 API 将在 2026 年停止接收错误修复。0.3.x 版本提供旧版 API,0.5.x 及以上版本均提供新版 API。

API Documentation

API 文档

The autogenerated API reference is hosted on CodeDocs. 自动生成的 API 参考文档托管在 CodeDocs 上。

Third Party Integrations

第三方集成

The following projects are not officially supported: 以下项目不受官方支持:

  • Qt wrapper
  • UnrealEngine Wrapper