Skip to content

Default MSVC static CRT for static yaml-cpp builds - #1484

Merged
SGSSGene merged 7 commits into
jbeder:masterfrom
harleywilsoneng:fix/msvc-static-crt-1354
Aug 14, 2026
Merged

Default MSVC static CRT for static yaml-cpp builds#1484
SGSSGene merged 7 commits into
jbeder:masterfrom
harleywilsoneng:fix/msvc-static-crt-1354

Conversation

@harleywilsoneng

Copy link
Copy Markdown
Contributor

Fixes #1354

Summary

  • Default YAML_MSVC_SHARED_RT to ${YAML_BUILD_SHARED_LIBS} so static yaml-cpp builds use /MT by default on MSVC.
  • Document static CRT behavior and YAML_CPP_STATIC_DEFINE for consumers linking the static library.

Test plan

  • Configure a static MSVC build and verify /MT is selected by default.
  • Configure with -DYAML_MSVC_SHARED_RT=ON and verify /MD is still available.

Signed-off-by: harleywilsoneng <harleywilsoneng@users.noreply.github.com>
Signed-off-by: harleywilsoneng <harleywilsoneng@users.noreply.github.com>
Signed-off-by: harleywilsoneng <harleywilsoneng@users.noreply.github.com>
Signed-off-by: harleywilsoneng <harleywilsoneng@users.noreply.github.com>
Signed-off-by: harleywilsoneng <harleywilsoneng@users.noreply.github.com>
Signed-off-by: harleywilsoneng <harleywilsoneng@users.noreply.github.com>
@SGSSGene

Copy link
Copy Markdown
Collaborator

Amazing! This is highly appreciated!

I took the liberty to convert it to a "draft" PR. Please convert it back to a normal PR when it is ready to be reviewed.

@SGSSGene
SGSSGene marked this pull request as draft August 13, 2026 04:59
@harleywilsoneng

Copy link
Copy Markdown
Contributor Author

Thanks @SGSSGene — marking this ready for review.

CI is green on the latest push (including Windows static consumer CRT alignment in test/cmake/CMakeLists.txt). Happy to adjust anything else if you'd like changes.

@harleywilsoneng
harleywilsoneng marked this pull request as ready for review August 13, 2026 10:27
@harleywilsoneng

Copy link
Copy Markdown
Contributor Author

Thanks @SGSSGene — marking this ready for review.

CI is green on the latest push (including Windows static consumer CRT alignment in test/cmake/CMakeLists.txt). Happy to adjust anything else if you'd like changes.

@SGSSGene SGSSGene left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for tackling this issue!
I only have a small remark about the README. Please feel free to reformulate my suggestion it in any other way!

Comment thread README.md Outdated
Comment on lines +32 to +34
the dynamic CRT (`/MD`) instead. When linking yaml-cpp statically into your project, define
`YAML_CPP_STATIC_DEFINE` in your target (or consume the `yaml-cpp::yaml-cpp` imported target,
which sets it automatically).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rewrite this slightly, It sounds like by default everyone should define YAML_CPP_STATIC_DEFINE.
I'd rather recommend consume target yaml-cpp::yaml-cpp and have the information about YAML_CPP_STATIC_DEFINE as a side note.

Suggested change
the dynamic CRT (`/MD`) instead. When linking yaml-cpp statically into your project, define
`YAML_CPP_STATIC_DEFINE` in your target (or consume the `yaml-cpp::yaml-cpp` imported target,
which sets it automatically).
the dynamic CRT (`/MD`) instead. When using cmake consume `yaml-cpp::yaml-cpp`, e.g.: `target_link_libraries(your_project_target yaml::yaml`.
(If cmake is not used you must define `YAML_CPP_STATIC_DEFINE` for your target.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — updated the README to lead with yaml-cpp::yaml-cpp, and mention YAML_CPP_STATIC_DEFINE only as the non-CMake fallback.

Signed-off-by: harleywilsoneng <harleywilsoneng@users.noreply.github.com>

@SGSSGene SGSSGene left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! thanks!

@SGSSGene
SGSSGene merged commit 14427ed into jbeder:master Aug 14, 2026
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MSVC 2022 Static Linking Problem

2 participants