Skip to content

Windows: Qt Debug dlls conflict with CXX-Qt #1234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
LeonMatthesKDAB opened this issue Mar 20, 2025 · 2 comments
Open

Windows: Qt Debug dlls conflict with CXX-Qt #1234

LeonMatthesKDAB opened this issue Mar 20, 2025 · 2 comments
Labels
⏮️ backport-candidate Change which could be backported to the stable series 🔨 build system Issues related to integrating CXX-Qt into CMake/Cargo

Comments

@LeonMatthesKDAB
Copy link
Collaborator

LeonMatthesKDAB commented Mar 20, 2025

On Windows, due to Rust always linking to the non-Debug runtime, Corrosion users need to do the same with all linked in C++ dependencies.
This includes Qt!

On Windows, Qt ships debug dlls that are built in debug mode and link to the debug runtime.
This is not compatible with CXX-Qt, and we must ensure that our users always link to the right Qt binaries (e.g. the non-Debug ones, even in a Debug build).

We may be able to fix this in cxx-qt-cmake for our users, otherwise we should emit a warning/error, like we do if you have set the incorrect MSVC runtime.

Otherwise, we may run into UB, as the debug and non-debug runtimes on Windows are not ABI-compatible!

Encountered by @narnaud in yesterdays training.

@LeonMatthesKDAB LeonMatthesKDAB added ⏮️ backport-candidate Change which could be backported to the stable series 🔨 build system Issues related to integrating CXX-Qt into CMake/Cargo labels Mar 20, 2025
@LeonMatthesKDAB LeonMatthesKDAB moved this to ToDo - 0.8 in Cxx-Qt 1.0 Mar 20, 2025
@LeonMatthesKDAB
Copy link
Collaborator Author

LeonMatthesKDAB commented Apr 9, 2025

The solution for this is outlined here:

rust-lang/rust#39016 (comment)

We can include this in cxx-qt-cmake with something like this:

target_link_options(<crate>-static INTERFACE /NODEFAULTLIB:msvcrt /DEFAULTLIB:msvcrtd)

Open Question: In a pure Cargo build, do we also link to the debug dlls automatically? If so, we need to emit the right linker flags in the build script as well.

LeonMatthesKDAB added a commit to LeonMatthesKDAB/cxx-qt that referenced this issue Apr 10, 2025
Once KDAB/cxx-qt-cmake#12 is merged, this should
no longer be necessary.

Closes KDAB#1234
LeonMatthesKDAB added a commit to LeonMatthesKDAB/cxx-qt that referenced this issue Apr 10, 2025
Once KDAB/cxx-qt-cmake#12 is merged, this should
no longer be necessary.

Closes KDAB#1234
LeonMatthesKDAB added a commit to LeonMatthesKDAB/cxx-qt that referenced this issue Apr 10, 2025
Once KDAB/cxx-qt-cmake#12 is merged, this should
no longer be necessary.

Closes KDAB#1234
@LeonMatthesKDAB
Copy link
Collaborator Author

LeonMatthesKDAB commented Apr 14, 2025

It turns out this unfortunately doesn't work as easily.
My example was still compiling with the "MultiThreadedDLL" option set and just linking to the debug runtime.
For some reason this worked, but seems very problematic.

The other approach would be to just always use the release runtime.
I finally figured out how to to do this.
You can tell CMake to map to the Release config of the Qt components with:

set_target_properties(Qt6::Core PROPERTIES MAP_IMPORTED_CONFIG_DEBUG "RELEASE")
set_target_properties(Qt6::Quick PROPERTIES MAP_IMPORTED_CONFIG_DEBUG "RELEASE")
set_target_properties(Qt6::Gui PROPERTIES MAP_IMPORTED_CONFIG_DEBUG "RELEASE")
set_target_properties(Qt6::Qml PROPERTIES MAP_IMPORTED_CONFIG_DEBUG "RELEASE")
set_target_properties(Qt6::QuickControls2 PROPERTIES MAP_IMPORTED_CONFIG_DEBUG "RELEASE")

Unfortunately this has to be done for all Qt packages that link into the final binary...
We should seriously consider improving the Rust ecosystems support for the debug runtime so that we can finally fix this for good.

LeonMatthesKDAB added a commit to LeonMatthesKDAB/cxx-qt-cmake that referenced this issue Apr 14, 2025
LeonMatthesKDAB added a commit to LeonMatthesKDAB/cxx-qt-cmake that referenced this issue Apr 15, 2025
LeonMatthesKDAB added a commit to KDAB/cxx-qt-cmake that referenced this issue Apr 15, 2025
LeonMatthesKDAB added a commit to LeonMatthesKDAB/cxx-qt-cmake that referenced this issue Apr 28, 2025
LeonMatthesKDAB added a commit to KDAB/cxx-qt-cmake that referenced this issue Apr 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⏮️ backport-candidate Change which could be backported to the stable series 🔨 build system Issues related to integrating CXX-Qt into CMake/Cargo
Projects
Status: ToDo - 0.8
Development

Successfully merging a pull request may close this issue.

1 participant