Repository navigation
Msvc static runtime - #2355
Merged
Merged
Msvc static runtime#2355
Conversation
Use CMake's standard CMAKE_MSVC_RUNTIME_LIBRARY (policy CMP0091) instead of a new option. Add a /MT leg for static-library builds to the MSVC CI job.
dmah42
reviewed
Oct 29, 2026
| cmake -S . -B build -DBENCHMARK_DOWNLOAD_DEPENDENCIES=ON -DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded$<$<CONFIG:Debug>:Debug>" | ||
| ``` | ||
|
|
||
| Use this instead of adding `/MT` to `CMAKE_CXX_FLAGS`; CMake selects the runtime from this setting. Combine it with the static library (`BUILD_SHARED_LIBS=OFF`), since a DLL with its own static C runtime can't safely share C runtime objects with the executable. |
Member
There was a problem hiding this comment.
do we need this line? do we say elsewhere in the docs to add /MT? if so maybe just remove that advice.
Contributor
Author
There was a problem hiding this comment.
Right, the docs don't actually mention adding /MT, so I removed that part to keep things accurate.
I nonetheless kept the note about limiting /MT to static libraries, since I ran into cross-CRT heap assertion failures when testing it with shared libraries locally.
dmah42
approved these changes
Oct 30, 2026
Member
|
our branch protection will need updating right after we merge. i'll update it after force merging this. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I have fixed #1655 by using CMake's existing CMAKE_MSVC_RUNTIME_LIBRARY setting instead of introducing a new project-specific option. This requires CMake 3.15 or later for deployment.
The MSVC CI job now tests both /MD and /MT configurations. The /MT configuration is restricted to static libraries, since using the static runtime with shared libraries can cause separate DLLs to manage their own runtime heaps. I also encountered __acrt_first_block == header debug assertion failures when testing the shared library and /MT combination locally.
The CI matrix increases from 8 to 12 jobs, with .MD and .MT added to job names to make the runtime configuration explicit.
Testing
I tested locally on Visual Studio 2022 (MSVC 19.44) with CMake 4.4.4 and all six targets use the static runtime in the /MT configuration. The test executable runs without requiring the MSVC runtime DLLs and all 87 tests pass.
However, I have not tested locally on Visual Studio 2026.
AI disclosure
I used an AI coding assistant to help investigate the CMake configuration and work through the implementation. I guided it humanly to execute the changes and I reviewed the resulting changes and tested the static-runtime configuration locally.