Skip to content

Commit 4b5f9d9

Browse files
Don't set MultiThreadedDLL for MSVC Debug builds
Once KDAB/cxx-qt-cmake#12 is merged, this should no longer be necessary. Closes KDAB#1234
1 parent 64d4ee6 commit 4b5f9d9

File tree

10 files changed

+25
-62
lines changed

10 files changed

+25
-62
lines changed

.github/workflows/github-cxx-qt-tests.yml

+12-4
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ jobs:
285285
clang_format_path: /home/runner/.local/bin/clang-format
286286
cargo_dir: ~/.cargo
287287
rustc_wrapper: sccache
288+
build_type: Release
288289
- name: Ubuntu 24.04 (gcc) Qt6
289290
os: ubuntu-24.04
290291
qt_version: 6
@@ -301,6 +302,7 @@ jobs:
301302
clang_format_path: /home/runner/.local/bin/clang-format
302303
cargo_dir: ~/.cargo
303304
rustc_wrapper: sccache
305+
build_type: Release
304306
packages-extra: >-
305307
libgl1-mesa-dev
306308
libvulkan-dev
@@ -327,6 +329,7 @@ jobs:
327329
cc: clang
328330
cxx: clang++
329331
rustc_wrapper: sccache
332+
build_type: Release
330333
- name: macOS 14 (clang) Qt6
331334
os: macos-14
332335
qt_version: 6
@@ -348,6 +351,7 @@ jobs:
348351
cc: clang
349352
cxx: clang++
350353
rustc_wrapper: sccache
354+
build_type: Release
351355

352356
- name: Windows 2022 (MSVC) Qt5
353357
os: windows-2022
@@ -366,6 +370,7 @@ jobs:
366370
cc: cl
367371
cxx: cl
368372
rustc_wrapper: sccache
373+
build_type: Release
369374
- name: Windows 2022 (MSVC2019) Qt6
370375
os: windows-2022
371376
qt_version: 6
@@ -383,7 +388,9 @@ jobs:
383388
cc: cl
384389
cxx: cl
385390
rustc_wrapper: sccache
386-
- name: Windows 2022 (MSVC2022) Qt6
391+
build_type: Release
392+
# Use a Debug build to ensure we can build and run tests in Debug mode with MSVC
393+
- name: Windows 2022 (MSVC2022) Qt6 Debug
387394
os: windows-2022
388395
qt_version: 6
389396
aqt_version: '6.8.0'
@@ -400,6 +407,7 @@ jobs:
400407
cc: cl
401408
cxx: cl
402409
rustc_wrapper: sccache
410+
build_type: Debug
403411

404412
runs-on: ${{ matrix.os }}
405413
name: ${{ matrix.name }}
@@ -536,23 +544,23 @@ jobs:
536544
run: >-
537545
cmake ${{ matrix.cmake_args }}
538546
-D USE_QT5=${{ matrix.qt_version == 5 }}
539-
-D CMAKE_BUILD_TYPE=Release
547+
-D CMAKE_BUILD_TYPE=${{ matrix.build_type }}
540548
-G Ninja
541549
-S . -B build
542550
env:
543551
RUSTC_WRAPPER: ${{ matrix.rustc_wrapper }}
544552
CC: ${{ matrix.cc }}
545553
CXX: ${{ matrix.cxx }}
546554
- name: "Build"
547-
run: cmake --build build --config Release --parallel ${{ matrix.cores }}
555+
run: cmake --build build --config ${{ matrix.build_type }} --parallel ${{ matrix.cores }}
548556
env:
549557
RUSTC_WRAPPER: ${{ matrix.rustc_wrapper }}
550558

551559
- name: "Print compiler cache statistics"
552560
run: sccache --show-stats
553561

554562
- name: "Test"
555-
run: ctest ${{ matrix.ctest_args }} -C Release -T test --output-on-failure --parallel ${{ matrix.cores }}
563+
run: ctest ${{ matrix.ctest_args }} -C ${{ matrix.build_type }} -T test --output-on-failure --parallel ${{ matrix.cores }}
556564
working-directory: ./build
557565
env:
558566
# Use the version of clang-format from pip

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4040
- CXX-Qt-build: Interface no longer includes compiler definitions (<https://github.com/KDAB/cxx-qt/issues/1165>)
4141
- CXX-Qt-build: Interface no longer includes initializers
4242

43+
### Fixed
44+
45+
- CXX-Qt-CMake can now link to the MSVC debug runtime, setting MultiThreadedDLL is no longer recommended.
46+
4347
## [0.7.1](https://github.com/KDAB/cxx-qt/compare/v0.7.0...v0.7.1) - 2025-03-04
4448

4549
### Added

book/src/getting-started/5-cmake-integration.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,13 @@ You should now see the two Labels that display the state of our `MyObject`, as w
207207

208208
### Windows with MSVC
209209

210-
If you're building CXX-Qt on Windows using MSVC generator, you need to ensure that `set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")` is set in CMake (or use the `-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL` flag) when building with the `Debug` configuration. This flag is necessary to ensure that the correct C Runtime Library is used. Then you can build using `cmake --build build --config Debug`.
210+
With MSVC, all parts of the build need to agree on the runtime that is linked into the executable.
211211

212-
This issue is caused by a bug in the [cc](https://docs.rs/cc/latest/cc/index.html) crate (as described in [this pull request](https://github.com/rust-lang/cc-rs/pull/717)), which has not been merged yet. Specifically, the problem is that cc generated code always links to the MultiThreaded runtime, even when building in Debug mode. We hope that this step won't be necessary in the future, once the cc crate fix is merged and released.
212+
As of CXX-Qt 0.7.2, cxx-qt-cmake will automatically set the right linker flags in the debug configuration.
213+
214+
The previous workaround of setting the CMAKE_MSVC_RUNTIME_LIBRARY to "MultiThreadedDLL" is no longer necessary or recommended!
215+
216+
See also:
217+
218+
- <https://corrosion-rs.github.io/corrosion/common_issues.html#linking-debug-cc-libraries-into-rust-fails-on-windows-msvc-targets>
219+
- <https://github.com/KDAB/cxx-qt/issues/1234>

examples/demo_threading/CMakeLists.txt

-8
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@ cmake_minimum_required(VERSION 3.24)
88
project(demo_threading)
99
set(APP_NAME ${PROJECT_NAME})
1010

11-
# Rust always links against non-debug Windows runtime on *-msvc targets
12-
# Note it is best to set this on the command line to ensure all targets are consistent
13-
# https://github.com/corrosion-rs/corrosion/blob/master/doc/src/common_issues.md#linking-debug-cc-libraries-into-rust-fails-on-windows-msvc-targets
14-
# https://github.com/rust-lang/rust/issues/39016
15-
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
16-
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
17-
endif()
18-
1911
if(BUILD_WASM)
2012
# Ensure Rust build for the correct target
2113
set(Rust_CARGO_TARGET wasm32-unknown-emscripten)

examples/qml_features/CMakeLists.txt

-8
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,6 @@ cmake_minimum_required(VERSION 3.24)
99
project(example_qml_features)
1010
set(APP_NAME ${PROJECT_NAME})
1111

12-
# Rust always links against non-debug Windows runtime on *-msvc targets
13-
# Note it is best to set this on the command line to ensure all targets are consistent
14-
# https://github.com/corrosion-rs/corrosion/blob/master/doc/src/common_issues.md#linking-debug-cc-libraries-into-rust-fails-on-windows-msvc-targets
15-
# https://github.com/rust-lang/rust/issues/39016
16-
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
17-
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
18-
endif()
19-
2012
if(BUILD_WASM)
2113
# Ensure Rust build for the correct target
2214
set(Rust_CARGO_TARGET wasm32-unknown-emscripten)

examples/qml_minimal/CMakeLists.txt

-8
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@
88
cmake_minimum_required(VERSION 3.24)
99

1010
project(example_qml_minimal)
11-
12-
# Rust always links against non-debug Windows runtime on *-msvc targets
13-
# Note it is best to set this on the command line to ensure all targets are consistent
14-
# https://github.com/corrosion-rs/corrosion/blob/master/doc/src/common_issues.md#linking-debug-cc-libraries-into-rust-fails-on-windows-msvc-targets
15-
# https://github.com/rust-lang/rust/issues/39016
16-
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
17-
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
18-
endif()
1911
# ANCHOR_END: book_cmake_setup
2012

2113
if(BUILD_WASM)

examples/qml_multi_crates/CMakeLists.txt

-8
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@ cmake_minimum_required(VERSION 3.24)
77

88
project(example_qml_multi_crates)
99

10-
# Rust always links against non-debug Windows runtime on *-msvc targets
11-
# Note it is best to set this on the command line to ensure all targets are consistent
12-
# https://github.com/corrosion-rs/corrosion/blob/master/doc/src/common_issues.md#linking-debug-cc-libraries-into-rust-fails-on-windows-msvc-targets
13-
# https://github.com/rust-lang/rust/issues/39016
14-
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
15-
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
16-
endif()
17-
1810
if(BUILD_WASM)
1911
# Ensure Rust build for the correct target
2012
set(Rust_CARGO_TARGET wasm32-unknown-emscripten)

tests/basic_cxx_only/CMakeLists.txt

-8
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,6 @@ cmake_minimum_required(VERSION 3.24)
99
project(tests_basic_cxx_only)
1010
set(APP_NAME ${PROJECT_NAME})
1111

12-
# Rust always links against non-debug Windows runtime on *-msvc targets
13-
# Note it is best to set this on the command line to ensure all targets are consistent
14-
# https://github.com/corrosion-rs/corrosion/blob/master/doc/src/common_issues.md#linking-debug-cc-libraries-into-rust-fails-on-windows-msvc-targets
15-
# https://github.com/rust-lang/rust/issues/39016
16-
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
17-
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
18-
endif()
19-
2012
# TODO: Add a helper function to our CMake module which automatically
2113
# handles some of this boilerplate for a "typical" Qt application
2214
set(CMAKE_AUTOMOC ON)

tests/basic_cxx_qt/CMakeLists.txt

-8
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,6 @@ cmake_minimum_required(VERSION 3.24)
99
project(tests_basic_cxx_qt)
1010
set(APP_NAME ${PROJECT_NAME})
1111

12-
# Rust always links against non-debug Windows runtime on *-msvc targets
13-
# Note it is best to set this on the command line to ensure all targets are consistent
14-
# https://github.com/corrosion-rs/corrosion/blob/master/doc/src/common_issues.md#linking-debug-cc-libraries-into-rust-fails-on-windows-msvc-targets
15-
# https://github.com/rust-lang/rust/issues/39016
16-
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
17-
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
18-
endif()
19-
2012
# TODO: Add a helper function to our CMake module which automatically
2113
# handles some of this boilerplate for a "typical" Qt application
2214
set(CMAKE_AUTOMOC ON)

tests/qt_types_standalone/CMakeLists.txt

-8
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,6 @@ cmake_minimum_required(VERSION 3.24)
99
project(tests_qt_types_standalone)
1010
set(APP_NAME ${PROJECT_NAME})
1111

12-
# Rust always links against non-debug Windows runtime on *-msvc targets
13-
# Note it is best to set this on the command line to ensure all targets are consistent
14-
# https://github.com/corrosion-rs/corrosion/blob/master/doc/src/common_issues.md#linking-debug-cc-libraries-into-rust-fails-on-windows-msvc-targets
15-
# https://github.com/rust-lang/rust/issues/39016
16-
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
17-
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
18-
endif()
19-
2012
# TODO: Add a helper function to our CMake module which automatically
2113
# handles some of this boilerplate for a "typical" Qt application
2214
set(CMAKE_AUTOMOC ON)

0 commit comments

Comments
 (0)