Skip to content
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

qml_minimal not compiling on Windows #625

Open
jacquetc opened this issue Jul 26, 2023 · 17 comments
Open

qml_minimal not compiling on Windows #625

jacquetc opened this issue Jul 26, 2023 · 17 comments
Labels
🪲 bug Something isn't working 🔨 build system Issues related to integrating CXX-Qt into CMake/Cargo

Comments

@jacquetc
Copy link
Contributor

Hello,

I'm trying out this nice crate. Already encountered issue #450 on MacOS (still investigating) and now trying it on Windows 10. I followed step by step your book, then I tried qml_minimal directly. Nothing compile.

Any idea ?

Regards,
Cyril

Steps to reproduce:

  • Qt Official Installer (open source)
  • Qt 5.6.1 MSVC2019 64bit
  • Rust 1.71
  • modify Cargo.toml to change versions and comment out the feature:
`# SPDX-FileCopyrightText: 2021 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
# SPDX-FileContributor: Andrew Hayzen <andrew.hayzen@kdab.com>
# SPDX-FileContributor: Gerhard de Clercq <gerhard.declercq@kdab.com>
#
# SPDX-License-Identifier: MIT OR Apache-2.0
# ANCHOR: book_all
[package]
name = "qml-minimal"
version = "0.1.0"
authors = [
  "Andrew Hayzen <andrew.hayzen@kdab.com>",
  "Gerhard de Clercq <gerhard.declercq@kdab.com>",
  "Leon Matthes <leon.matthes@kdab.com>"
]
edition = "2021"
license = "MIT OR Apache-2.0"

# This will instruct Cargo to create a static
# library which CMake can link against
# ANCHOR: book_static_lib
[lib]
crate-type = ["staticlib"]
# ANCHOR_END: book_static_lib

# ANCHOR: book_dependencies
[dependencies]
# Use `cxx = "1.0.95"` here instead!
cxx = "1.0.95"
# Use `cxx-qt = "0.5"` here instead!
cxx-qt = "0.5.3"
# Use `cxx-qt-lib = "0.5"` here instead!
cxx-qt-lib = "0.5.3"
# ANCHOR_END: book_dependencies

# cxx-qt-build generates C++ code from the `#[cxx_qt::bridge]` module
# and compiles it together with the Rust static library
# ANCHOR: book_build_dsependencies
[build-dependencies]
# Use `cxx-qt-build = "0.5"` here instead!
cxx-qt-build = "0.5.3"

[features]
# This feature must be enabled for `cargo test` when linking Qt 6 statically.
# link_qt_object_files = [ "cxx-qt-build/link_qt_object_files" ]
# ANCHOR_END: book_build_dependencies

# ANCHOR_END: book_all

  • Comment out in CMakeLists.txt
    add_valgrind_test(
        ${APP_TEST_NAME} "${TEST_CMD}" ${CMAKE_CURRENT_BINARY_DIR}
    )
  • Run from Qt Creator

Expected behavior:

  • Compilation runs

Current behavior:

  • Cmake configuration runs well
  • Compilation fails :
   Compiling qml-minimal v0.1.0 (C:\Users\cyril\Devel\qml_minimal\rust)
error: failed to run custom build command for `qml-minimal v0.1.0 (C:\Users\cyril\Devel\qml_minimal\rust)`

Caused by:
  process didn't exit successfully: `C:/Users/cyril/Devel/build-qml_minimal-Desktop_Qt_6_5_2_MSVC2019_64bit-Debug/./cargo/build\debug\build\qml-minimal-2701a55ebb4a1e87\build-script-build` (exit code: 101)
  --- stdout
  cargo:rerun-if-changed=src/cxxqt_object.rs
  cargo:rerun-if-env-changed=QMAKE
  cargo:rerun-if-env-changed=QT_VERSION_MAJOR
  cargo:rustc-link-search=C:/Qt/6.5.2/msvc2019_64/lib
  cargo:rustc-link-lib=Qt6Core
  cargo:rustc-link-lib=Qt6Gui
  cargo:rustc-link-lib=Qt6Qml
  cargo:rerun-if-changed=C:\Users\cjacquet\Devel\qml_minimal\rust/src/cxxqt_object.rs

  --- stderr
  thread 'main' panicked at 'Could not generate C++ from Rust file: Syn(Error(["unrecognized ABI, requires either \"C++\" or \"Rust\"", "unrecognized ABI, requires either \"C++\" or \"Rust\""]))', C:\Users\cyril\.cargo\registry\src\index.crates.io-6f17d22bba15001f\cxx-qt-build-0.5.3\src\lib.rs:127:14
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
@ahayzen-kdab
Copy link
Collaborator

Thanks for taking to time to report this issue and help make CXX-Qt better.

Are you able to provide the contents of your rust file (i assume src/cxxqt_object.rs) or put the whole folder into a git repository somewhere so we can see it ?

I wonder if what has happened is have you taken the cxxqt_object.rs file from the main branch and are trying to use it against CXX-Qt version 0.5.3 ? As we are going through an API change in the main branch for the 0.6.x series which introduces new ABI to the extern blocks. If this is the case then you should use the files in https://github.com/KDAB/cxx-qt/tree/0.5.x for CXX-Qt 0.5.3

Also if you are able to provide any debug information for #450 that would be much appreciated as there are many different possible combinations of setups 😅

@ahayzen-kdab ahayzen-kdab added the 🪲 bug Something isn't working label Jul 26, 2023
@jacquetc
Copy link
Contributor Author

Thank you for your help, it's much appreciated.

I'll gladly help for #450 :D

Your first assumption was good : I was at the latest commit of the main branch. So that's exactly what happened. I made the assumption that the main branch was stable, forgot that you were still in 0.x.x, meaning unstable . My bad, sorry.

Now, based on the qml_minimal on tag 0.5.3, the error was passed, but another appeared.



  cargo:warning=C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/as.exe: C:/Users/cjacquet/Devel/build-qml_minimal-Desktop_Qt_6_5_2_MinGW_64_bit-Debug/./cargo/build\x86_64-pc-windows-gnu\debug\build\cxx-qt-lib-91f296d80526917a\out\src/core/qlist/qlist.o: too many sections (34548)
  cargo:warning=C:\Users\cjacquet\AppData\Local\Temp\ccVhPBJj.s: Assembler messages:
  cargo:warning=C:\Users\cjacquet\AppData\Local\Temp\ccVhPBJj.s: Fatal error: can't write 18 bytes to section .text$_ZnwyPv of C:/Users/cjacquet/Devel/build-qml_minimal-Desktop_Qt_6_5_2_MinGW_64_bit-Debug/./cargo/build\x86_64-pc-windows-gnu\debug\build\cxx-qt-lib-91f296d80526917a\out\src/core/qlist/qlist.o: 'file too big'
  cargo:warning=C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/as.exe: C:/Users/cjacquet/Devel/build-qml_minimal-Desktop_Qt_6_5_2_MinGW_64_bit-Debug/./cargo/build\x86_64-pc-windows-gnu\debug\build\cxx-qt-lib-91f296d80526917a\out\src/core/qlist/qlist.o: too many sections (34548)
  cargo:warning=C:\Users\cjacquet\AppData\Local\Temp\ccVhPBJj.s: Fatal error: C:/Users/cjacquet/Devel/build-qml_minimal-Desktop_Qt_6_5_2_MinGW_64_bit-Debug/./cargo/build\x86_64-pc-windows-gnu\debug\build\cxx-qt-lib-91f296d80526917a\out\src/core/qlist/qlist.o: file too big
  exit code: 1
  cargo:warning=C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/as.exe: C:/Users/cjacquet/Devel/build-qml_minimal-Desktop_Qt_6_5_2_MinGW_64_bit-Debug/./cargo/build\x86_64-pc-windows-gnu\debug\build\cxx-qt-lib-91f296d80526917a\out\src/core/qvector/qvector.o: too many sections (34548)
  cargo:warning=C:\Users\cjacquet\AppData\Local\Temp\ccPQ2Bf3.s: Assembler messages:
  cargo:warning=C:\Users\cjacquet\AppData\Local\Temp\ccPQ2Bf3.s: Fatal error: can't write 18 bytes to section .text$_ZnwyPv of C:/Users/cjacquet/Devel/build-qml_minimal-Desktop_Qt_6_5_2_MinGW_64_bit-Debug/./cargo/build\x86_64-pc-windows-gnu\debug\build\cxx-qt-lib-91f296d80526917a\out\src/core/qvector/qvector.o: 'file too big'
  cargo:warning=C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/as.exe: C:/Users/cjacquet/Devel/build-qml_minimal-Desktop_Qt_6_5_2_MinGW_64_bit-Debug/./cargo/build\x86_64-pc-windows-gnu\debug\build\cxx-qt-lib-91f296d80526917a\out\src/core/qvector/qvector.o: too many sections (34548)
  cargo:warning=C:\Users\cjacquet\AppData\Local\Temp\ccPQ2Bf3.s: Fatal error: C:/Users/cjacquet/Devel/build-qml_minimal-Desktop_Qt_6_5_2_MinGW_64_bit-Debug/./cargo/build\x86_64-pc-windows-gnu\debug\build\cxx-qt-lib-91f296d80526917a\out\src/core/qvector/qvector.o: file too big
  exit code: 1

  --- stderr

  CXX include path:
    C:/Users/cjacquet/Devel/build-qml_minimal-Desktop_Qt_6_5_2_MinGW_64_bit-Debug/./cargo/build\x86_64-pc-windows-gnu\debug\build\cxx-qt-lib-91f296d80526917a\out\cxxbridge\include
    C:/Users/cjacquet/Devel/build-qml_minimal-Desktop_Qt_6_5_2_MinGW_64_bit-Debug/./cargo/build\x86_64-pc-windows-gnu\debug\build\cxx-qt-lib-91f296d80526917a\out\cxxbridge\crate
    C:/Qt/6.5.2/mingw_64/include/QtCore
    C:/Qt/6.5.2/mingw_64/include/QtGui
    C:/Qt/6.5.2/mingw_64/include/QtQml
    C:/Qt/6.5.2/mingw_64/include


  error occurred: Command "C:/Qt/Tools/mingw1120_64/bin/g++.exe" "-O0" "-ffunction-sections" "-fdata-sections" "-gdwarf-2" "-fno-omit-frame-pointer" "-m64" "-I" "C:/Users/cjacquet/Devel/build-qml_minimal-Desktop_Qt_6_5_2_MinGW_64_bit-Debug/./cargo/build\\x86_64-pc-windows-gnu\\debug\\build\\cxx-qt-lib-91f296d80526917a\\out\\cxxbridge\\include" "-I" "C:/Users/cjacquet/Devel/build-qml_minimal-Desktop_Qt_6_5_2_MinGW_64_bit-Debug/./cargo/build\\x86_64-pc-windows-gnu\\debug\\build\\cxx-qt-lib-91f296d80526917a\\out\\cxxbridge\\crate" "-I" "C:/Qt/6.5.2/mingw_64/include/QtCore" "-I" "C:/Qt/6.5.2/mingw_64/include/QtGui" "-I" "C:/Qt/6.5.2/mingw_64/include/QtQml" "-I" "C:/Qt/6.5.2/mingw_64/include" "-I" "C:/Users/cjacquet/Devel/build-qml_minimal-Desktop_Qt_6_5_2_MinGW_64_bit-Debug/./cargo/build\\x86_64-pc-windows-gnu\\debug\\build\\cxx-qt-lib-91f296d80526917a\\out" "-Wall" "-Wextra" "-std=c++17" "-DCXX_QT_GUI_FEATURE" "-DCXX_QT_QML_FEATURE" "-o" "C:/Users/cjacquet/Devel/build-qml_minimal-Desktop_Qt_6_5_2_MinGW_64_bit-Debug/./cargo/build\\x86_64-pc-windows-gnu\\debug\\build\\cxx-qt-lib-91f296d80526917a\\out\\src/core/qlist/qlist.o" "-c" "src/core/qlist/qlist.cpp" with args "g++.exe" did not execute successfully (status code exit code: 1).

@ahayzen-kdab
Copy link
Collaborator

That's a fun error :-) sounds like we might need to set bigobj maybe.

However I would also note that before you were using MSVC2019_64bit-Debug (which we test in CI) and now you are using the toolchain MinGW_64_bit-Debug (which we don't test and might need like -Wa,-mbig-obj set).

Could you try using MSVC2019 again ?

@ahayzen-kdab
Copy link
Collaborator

I made the assumption that the main branch was stable, forgot that you were still in 0.x.x, meaning unstable . My bad, sorry.

No problem, FYI this new API we are writing for 0.6 we are hoping to use as the base to start stabilising for 1.0 :-) (as seen in #555 )

@ahayzen-kdab ahayzen-kdab added the 🔨 build system Issues related to integrating CXX-Qt into CMake/Cargo label Jul 26, 2023
@jacquetc
Copy link
Contributor Author

Sorry, I'll be able to test it this evening

@jacquetc
Copy link
Contributor Author

Hello,

The Windows computer wasn't available tonight, so will test it again tomorrow.

Yet, as promised, I helped on #450 and I propose a fix at #630

@jacquetc
Copy link
Contributor Author

I started again from scratch:

  • on CXX-QT 0.5.3, and copied again the qml_minimal outside the cxx-qt folder, and commented valgrind line in CMakeLists.txt
  • Followed the documentation for the Cargo.toml (build against cxx 0.83 and cxx-qt 0.5)
  • Open this project CMakeLists.txt in QT Creator against Qt 6.5.2
  • CMake configuration runs fine
  • Compilation crashes, complete log:
    compile_log.txt

Interesting:

qml_minimal.lib(std-f54c5a8dc7e7febf.std.1153952cb135a7f6-cgu.0.rcgu.o) : error LNK2019: symbole externe non résolu __imp_NtCreateFile référencé dans la fonction _ZN3std3sys7windows2fs20open_link_no_reparse17ha8439d4ac49b3913E
qml_minimal.lib(std-f54c5a8dc7e7febf.std.1153952cb135a7f6-cgu.0.rcgu.o) : error LNK2019: symbole externe non résolu __imp_RtlNtStatusToDosError référencé dans la fonction _ZN3std3sys7windows2fs20open_link_no_reparse17ha8439d4ac49b3913E
qml_minimal.lib(std-f54c5a8dc7e7febf.std.1153952cb135a7f6-cgu.0.rcgu.o) : error LNK2019: symbole externe non résolu __imp_NtReadFile référencé dans la fonction _ZN3std3sys7windows6handle6Handle16synchronous_read17hfd3297a2d25b288dE
qml_minimal.lib(std-f54c5a8dc7e7febf.std.1153952cb135a7f6-cgu.0.rcgu.o) : error LNK2019: symbole externe non résolu __imp_NtWriteFile référencé dans la fonction _ZN3std3sys7windows6handle6Handle17synchronous_write17h1f1222e834ac3046E
example_qml_minimal.exe : fatal error LNK1120: 4 externes non résolus

Compile args gererated by Qt Creator: compile_args.txt

Is it worth to investagate on 0.5.3 ? Do you want me to test it on the latest from main branch ?

@ahayzen-kdab
Copy link
Collaborator

This is on Windows right ? This is likely due to the corrosion bug in combination with Rust 1.71 see

corrosion-rs/corrosion#418

Try bumping your corrosion version to 0.4.2 as in #609

@jacquetc
Copy link
Contributor Author

Yes, Windows 10 (22H2). That was exactly the solution for this bug. Now it runs fine. Thank you !

For fun, I was testing out from the latest main 0af59b , with Cargo.toml deps pointing to the path of the corresponding crates in the local cxx-qt repo.

Qt 6.5.2 official installer with Qt Creator 11:

@ahayzen-kdab
Copy link
Collaborator

MinGW debug looks like it needs bigobj enabling, MSCV debug looks like a more interesting failure to investigate.

@jacquetc
Copy link
Contributor Author

I'll find out what "bigobj" means tonight :D . I'm at your disposition for the other failure. Maybe we can close this ticket as resolved and open a new one dedicated to this MSCV failure ?

@ahayzen-kdab
Copy link
Collaborator

We might need to set the equivalent of -Wa,-mbig-obj in MinGW and /bigobj for MSVC

Note we already have some settings in cxx-qt-build and cxx-qt-lib, so these might just need adding there to make things happier.

            // MSVC
            builder.flag_if_supported("/std:c++17");
            builder.flag_if_supported("/Zc:__cplusplus");
            builder.flag_if_supported("/permissive-");
            // GCC + Clang
            builder.flag_if_supported("-std=c++17");

https://learn.microsoft.com/en-us/cpp/build/reference/bigobj-increase-number-of-sections-in-dot-obj-file?view=msvc-170
https://stackoverflow.com/questions/16596876/gcc-equivalent-of-mss-bigobj

You could open a new issue or just reuse this one for compile issues on Windows.

@jacquetc
Copy link
Contributor Author

We will continue with this issue since the title is still valid. With your agreement, I'll implement & test the flags for MinGW this weekend.

@ahayzen-kdab
Copy link
Collaborator

Cool thanks!

@jacquetc
Copy link
Contributor Author

Hello,

I tested builder.flag_if_supported("-Wa,-mbig-obj"), always the same error. Qt uses MinGW-W64, so bigobj is normally supported. It's hard to determine if the argument was really passed to the compiler. Investigating more.

@ahayzen-kdab
Copy link
Collaborator

ahayzen-kdab commented Jul 31, 2023

Note you would need to adjust the builder in both cxx-qt-lib/build.rs and cxx-qt-build/src/lib.rs. But as you say maybe this is not the issue :-)

@jacquetc
Copy link
Contributor Author

jacquetc commented Aug 1, 2023

Done, tested successfully. PR #644 created

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🪲 bug Something isn't working 🔨 build system Issues related to integrating CXX-Qt into CMake/Cargo
Projects
None yet
Development

No branches or pull requests

2 participants