yaml-cpp: A C++ YAML Parser and Emitter
yaml-cpp is a C++ library for parsing and emitting YAML that targets the YAML 1.2 specification. It builds through CMake as a static library by default, or shared with one flag, and drops into a CMake project via FetchContent. Reach for it when you want a spec-conformant YAML layer with little build ceremony; skip it if you're not ready to pick between its current API and the older 0.3.0-era one.
Understanding yaml-cpp
yaml-cpp is a C++ parser and emitter for YAML files, built to track the YAML 1.2 specification from yaml.org. It compiles as a CMake project — static by default, shared with one flag — and its README points to wiki pages for parsing and emitting rather than inlining code samples. The current API arrived with the 0.5.0 release; an older interface remains available via the 0.3.0 release.
Core Capabilities
- ✓Parses and emits YAML against the YAML 1.2 specification, per the README.
- ✓CMake-driven cross-platform build that produces a static library by default and a shared one with the -DYAML_BUILD_SHARED_LIBS=ON flag.
- ✓Drops into a CMake project through FetchContent, exposing a yaml-cpp::yaml-cpp target for target_link_libraries.
- ✓Two documented API generations: the current one shipped since the 0.5.0 release, and an older interface still available in the 0.3.0 release for existing code.
- ✓Debug-mode support: compiling both yaml-cpp and the code that links it with the _GLIBCXX_DEBUG flag, plus a CMake option, YAML_USE_SYSTEM_GTEST (off by default), for building its own GoogleTest instead of the system one.
- ✓Autogenerated API reference published on CodeDocs rather than hand-written docs pages.
- ✓Unofficial third-party wrappers exist for Qt and Unreal Engine, linked from the README, though neither is maintained by the yaml-cpp project itself.
Building and Integrating yaml-cpp
The README lays out CMake steps rather than a package-manager install. Create a build directory (mkdir build, then cd build), then run cmake with an optional -G <generator> flag and -DYAML_BUILD_SHARED_LIBS=ON if you want a shared library instead of the static default; leaving out -G targets a Makefile on Unix-like systems, while Windows and macOS typically use a Visual Studio or Xcode generator. If you skipped the platform installer for CMake, put its bin directory on your PATH first. The build command after that depends on which generator you picked, and cleaning up is just deleting the build folder. To pull yaml-cpp into another CMake project instead of building it standalone, the README recommends FetchContent: declare the yaml-cpp git repository with a tag, commit hash, or branch, call FetchContent_MakeAvailable, then link the yaml-cpp::yaml-cpp target into your own target. Further build options live in the project's CMakeLists.txt file.
Parsing and Emitting YAML
The README doesn't inline parsing or emitting code samples — it defers to two wiki pages: a Tutorial for reading YAML and a How to Emit YAML guide for writing it back out. Code still targeting the interface from before the 0.5.0 release has its own separate wiki reference covering that older parsing surface. Beyond those links, there's no usage walkthrough in the facts available here, so the wiki is the actual source for API calls and code examples.
Strengths
- ✓Targets the full YAML 1.2 specification rather than a partial subset, per the README.
- ✓FetchContent integration is a short CMakeLists.txt block — declare the repo, call FetchContent_MakeAvailable, link yaml-cpp::yaml-cpp.
- ✓MIT license, so it drops into another project's dependency tree without copyleft strings attached.
- ✓One flag (-DYAML_BUILD_SHARED_LIBS=ON) switches the build from static to shared without touching anything else.
- ✓Keeps an old 0.3.0 release available for projects that haven't migrated off the pre-0.5.0 API, instead of forcing an immediate rewrite.
Considerations for Adoption
- △The README itself has no inline parsing or emitting code examples — you leave the repo for the wiki's Tutorial page and its separate emitting guide to see actual API calls.
- △The old, pre-0.5.0 API stops getting bugfixes once 2026 arrives, per the README, so code still on the 0.3.0 line is on a defined clock to migrate.
- △No changelog or per-version breaking-change notes appear in the facts here beyond the 0.9.0 and 0.3.0 release links, so upgrade risk between versions isn't documented.
- △Only CMake build instructions are documented — no vcpkg, Conan, or other package-manager install path appears in the README.
- △The Qt and Unreal Engine wrappers linked from the README are both flagged as unofficial and not supported by the yaml-cpp project itself.
Other C++ YAML Libraries
Frequently Asked Questions
yaml-cpp is released under the MIT license, as listed on its GitHub repository page.
yaml-cpp parses and emits YAML built to track the YAML 1.2 specification, according to its README.
Create a build directory, run cmake from inside it — optionally with -G <generator> and -DYAML_BUILD_SHARED_LIBS=ON for a shared library instead of the static default — then run the build command for whichever generator you picked. Leaving out -G targets a Makefile on Unix-like systems.
yaml-cpp's 0.3.0 release keeps the old, pre-0.5.0 API available for projects that haven't migrated yet. The README notes that old API line stops receiving bugfixes once 2026 arrives, so treat it as a bridge, not a permanent option.
Declare yaml-cpp with CMake's FetchContent module — a GIT_REPOSITORY pointed at the yaml-cpp repo and a GIT_TAG for the tag, commit, or branch you want — call FetchContent_MakeAvailable(yaml-cpp), then link the yaml-cpp::yaml-cpp target into your own target with target_link_libraries.
yaml-cpp publishes an autogenerated API reference on CodeDocs, linked directly from the project's README.
The problem it solves
C++ has no YAML parser or emitter in its standard library, so a project that reads YAML config or CI files, or writes YAML back out, either hand-rolls a partial reader or pulls in a dependency. yaml-cpp targets that gap specifically for CMake-based C++ projects: it aims at full YAML 1.2 conformance rather than a subset, and it integrates through FetchContent so adding it is a CMakeLists.txt block instead of a separate package manager step.
Best use cases
- •Reading YAML configuration files inside a C++ application or service instead of parsing them by hand.
- •Emitting YAML back out — for generated config, exported data, or test fixtures — using the emitter half of the API covered in the How to Emit YAML wiki page.
- •Pulling yaml-cpp into an existing CMake-based C++ build with FetchContent instead of vendoring a parser.
- •Wrapping yaml-cpp inside a Qt or Unreal Engine project via the unofficial third-party wrappers the README links to.
- •Staying on the 0.3.0 release temporarily while migrating code still written against the pre-0.5.0 API.
Who should try it — and who should skip
Try yaml-cpp if you're building a C++ project that already uses CMake and you want YAML 1.2 conformance without hand-rolling a parser — the FetchContent path and the static/shared build flag make it a low-friction dependency to add. Skip it if you want a header-only library with zero build-system involvement, or if you're not ready to commit to the current API versus the 0.3.0-era old one, since the README is explicit that the old line's bugfix window ends in 2026.
Want a second opinion on yaml-cpp?
Ask an AI that can read this page — one click and you get its take on yaml-cpp.
