Skip to content

QML Modules defined in external crates don't work #1135

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

Closed
akiselev opened this issue Nov 27, 2024 · 9 comments · Fixed by #1178
Closed

QML Modules defined in external crates don't work #1135

akiselev opened this issue Nov 27, 2024 · 9 comments · Fixed by #1178
Assignees
Labels
⏮️ backport-candidate Change which could be backported to the stable series 🪲 bug Something isn't working 🔨 build system Issues related to integrating CXX-Qt into CMake/Cargo

Comments

@akiselev
Copy link
Contributor

Repro: https://github.com/akiselev/cxx-qt-module-repro

Current output:

Default MyObjectRust MyObjectRust { number: 0, string:  }
QQmlApplicationEngine failed to load component
file:///.../cxx-qt-module-repro/qml/main.qml:13:1: module "CxxQt.Repro" is not installed

@LeonMatthes said in Zulip:

  • All your crates should use CXX-Qt 0.7 (or git main)
  • All library crates need to use the CxxQtBuilder::library function
  • All library crates need to have a links key set in their Cargo.toml
  • Your main executable needs to build with a normal CxxQtBuilder::new, even if it doesn't actually need to build anything itself.

I think I've got all that covered but the repro still fails to load the module correct. In my own project, this works with CMake but not Cargo.

@LeonMatthesKDAB LeonMatthesKDAB self-assigned this Dec 6, 2024
@LeonMatthesKDAB LeonMatthesKDAB added 🪲 bug Something isn't working 🔨 build system Issues related to integrating CXX-Qt into CMake/Cargo ⏮️ backport-candidate Change which could be backported to the stable series labels Dec 6, 2024
LeonMatthesKDAB added a commit to LeonMatthesKDAB/cxx-qt that referenced this issue Dec 6, 2024
See: KDAB#1135
Note: This is not yet final, as this probably makes cxx_qt_import_qml_module
redundant.
@LeonMatthesKDAB
Copy link
Collaborator

LeonMatthesKDAB commented Dec 6, 2024

@akiselev Thank you for taking the time to report the issue and especially to create the reproducable example. That has really helped with troubleshooting.

I was able to reproduce the issue and to find the root cause.
QML modules actually build and link their own initializers, but don't export them to downstream dependencies.

With CMake, this isn't necessarily a problem, as you import the QML module separately via cxxqt_import_qml_module, which then includes the object file in the build system (though you then have to import the crate that contains the qml module separately as well).

With Cargo-only builds, our assumption was that linking the object file directly would cause it to not be optimized out at the linking stage, even for dependencies.
However, this assumption seems to have been incorrect, as Rust seems to still link the dependencies into a static library or something similar before building the final executable.
This then ends up optimizing the initializer out again.
cc @ahayzen-kdab

While the fix for cargo-only builds is quite simple (see: https://github.com/LeonMatthesKDAB/cxx-qt/tree/7952f55c1529df8d8a67b2278ea12d67f885412d ), a solution that also fixes the CMake integration needs a bit more thought.

@LeonMatthesKDAB LeonMatthesKDAB moved this from Todo to ToDo - 0.8 in Cxx-Qt 1.0 Dec 6, 2024
@akiselev
Copy link
Contributor Author

akiselev commented Dec 15, 2024

While the fix for cargo-only builds is quite simple (see: https://github.com/KDAB/cxx-qt/tree/7952f55c1529df8d8a67b2278ea12d67f885412d ), a solution that also fixes the CMake integration needs a bit more thought.

@LeonMatthesKDAB is there more to this fix than what I am seeing in the commit?

When trying your modifications locally with my repro repo, I get the following error:

cxx-qt-module-repro/target/debug/build/cxx-qt-module-repro-6f063905c3a6c913/out/cxx-qt-build/initializers/cxx-qt-module-repro.cpp:192: error: undefined reference to 'qt_static_plugin_CxxQt_Repro_plugin()'

I get a similar error when building my main repo.

Edit: I just cloned your fork to that commit and tried to build it, to the same result.

I took a look using nm:

$ nm ./target/debug/deps/libqmlmod-35ac850a31af56d3.a
0000000000000000 T _Z35qt_static_plugin_CxxQt_Repro_pluginv

The linker stage links /target/debug/deps/libqmlmod-35ac850a31af56d3.rlib but doesn't see the static initializers

@LeonMatthesKDAB
Copy link
Collaborator

Hi @akiselev , thanks for pointing out that the link is wrong, I updated it to point to my fork instead.

In your repro example, I'm on commit 695dd3a71a6331c460ac5a6a6cb0c26fbf83e47c and the only diff is:

─────────────────────────────────────────────────────┐
• Cargo.toml:24: cxx-qt-build = { workspace = true } │
─────────────────────────────────────────────────────┴──────────────────────────────────────────────────────────────────────────
 24 ⋮ 24 │
 25 ⋮ 25 │[workspace.dependencies]
 26 ⋮ 26 │cxx = "1.0.94"
 27 ⋮    │cxx-qt = { version = "0.7"}
 28 ⋮    │cxx-qt-lib = { version = "0.7"}
 29 ⋮    │cxx-qt-lib-extras = { version = "0.7"}
 30 ⋮    │cxx-qt-build = { version = "0.7"}
 31 ⋮    │qt-build-utils = { version = "0.7"}
\ No newline at end of file
    ⋮ 27 │cxx-qt = { git="https://github.com/LeonMatthesKDAB/cxx-qt/", rev="7952f55c1529df8d8a67b2278ea12d67f885412d" }
    ⋮ 28 │cxx-qt-lib = { git="https://github.com/LeonMatthesKDAB/cxx-qt/", rev="7952f55c1529df8d8a67b2278ea12d67f885412d" }
    ⋮ 29 │cxx-qt-lib-extras = { git="https://github.com/LeonMatthesKDAB/cxx-qt/", rev="7952f55c1529df8d8a67b2278ea12d67f885412d" }
    ⋮ 30 │cxx-qt-build = { git="https://github.com/LeonMatthesKDAB/cxx-qt/", rev="7952f55c1529df8d8a67b2278ea12d67f885412d" }
    ⋮ 31 │qt-build-utils = { git="https://github.com/LeonMatthesKDAB/cxx-qt/", rev="7952f55c1529df8d8a67b2278ea12d67f885412d" }

So I just updated the cxx-qt repo to the commit I sent you.

If I then do cargo run I get this:
image

So that should work...

@LeonMatthesKDAB
Copy link
Collaborator

I also added a fork of the repro example here: https://github.com/LeonMatthesKDAB/cxx-qt-module-repro

You should just be able to clone it and do cargo run 🤔

@akiselev
Copy link
Contributor Author

I tried building your repo and got the same error (cleaned up a little and added multilines):

error: linking with `cc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/home/dev/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/dev/.console-ninja/.bin:/home/dev/.pyenv/shims:/usr/lib/qt6/bin:/home/dev/git/kde/src/kdesrc-build:/home/dev/scripts/bin:/home/dev/scripts:/home/dev/.local/bin:/home/dev/.cargo/bin:/home/dev/.nvm/versions/node/v20.18.1/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl" VSLANG="1033" \
  "cc" "-m64" \
    "/tmp/rustcggK7Nk/symbols.o" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/cxx_qt_module_repro-dbbbaf0ad2e1f035.0jaj2n4uod7ozhsxd1nyoqt70.rcgu.o" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/cxx_qt_module_repro-dbbbaf0ad2e1f035.101k3jgnc7g0xe6sj2t7ov5rb.rcgu.o" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/cxx_qt_module_repro-dbbbaf0ad2e1f035.1itm935u59v122qj9sl00npdv.rcgu.o" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/cxx_qt_module_repro-dbbbaf0ad2e1f035.2b6dm1o0f559nj7np8qy35nut.rcgu.o" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/cxx_qt_module_repro-dbbbaf0ad2e1f035.3rt9s1kiwg7dajhycvhxc8yu7.rcgu.o" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/cxx_qt_module_repro-dbbbaf0ad2e1f035.476ez4q8csawl9tt9yk5xly7j.rcgu.o" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/cxx_qt_module_repro-dbbbaf0ad2e1f035.48nvozbi7nwgkc8lwebyu2pfo.rcgu.o" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/cxx_qt_module_repro-dbbbaf0ad2e1f035.4pe214l4f6ow9ki8aq1vprs03.rcgu.o" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/cxx_qt_module_repro-dbbbaf0ad2e1f035.4sbemze3jl8wb68lwoj88dg3s.rcgu.o" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/cxx_qt_module_repro-dbbbaf0ad2e1f035.8uj2l6s2fivytmdpl92lguqbh.rcgu.o" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/cxx_qt_module_repro-dbbbaf0ad2e1f035.aqksngsz9slwacppcdbp3jox9.rcgu.o" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/cxx_qt_module_repro-dbbbaf0ad2e1f035.b50q2tzvlsjqzh6mug1v3qyxd.rcgu.o" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/cxx_qt_module_repro-dbbbaf0ad2e1f035.c4umquu886v1olk6j7wfmldyj.rcgu.o" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/cxx_qt_module_repro-dbbbaf0ad2e1f035.c98dfjmkp3fr7owlax14epqdd.rcgu.o" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/cxx_qt_module_repro-dbbbaf0ad2e1f035.dbbn9tqzm5p7huhyl3wr67vy3.rcgu.o" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/cxx_qt_module_repro-dbbbaf0ad2e1f035.drq5rwaurmsjib98e1ye11zs8.rcgu.o" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/cxx_qt_module_repro-dbbbaf0ad2e1f035.e6ggiuikfr5pmumf0h9318d9l.rcgu.o" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/cxx_qt_module_repro-dbbbaf0ad2e1f035.ea8kz4ogm1ak3z76n0r6vbtee.rcgu.o" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/cxx_qt_module_repro-dbbbaf0ad2e1f035.eptinhstjlxaq16naz2z3yb55.rcgu.o" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/cxx_qt_module_repro-dbbbaf0ad2e1f035.5fc3xr0g912prkycqdbu495j9.rcgu.o" \
    "-Wl,--as-needed" "-Wl,-Bdynamic" \
    "-lQt6QuickControls2" \
    "-lQt6Quick" \
    "-lQt6QmlMeta" \
    "-lQt6QmlWorkerScript" \
    "-lQt6QmlModels" \
    "-lQt6OpenGL" \
    "-lQt6Gui" \
    "-lGLX" \
    "-lOpenGL" \
    "-lQt6Qml" \
    "-lQt6Network" \
    "-lQt6Core" \
    "-Wl,-Bstatic" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libqmlmod-60563a806f7c4247.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libcxx_qt_lib-c37f6a0c51ab6baf.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/librgb-0325f8af52c792aa.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libbytemuck-001c838fec11c0a7.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/liburl-41fc2269db200f1a.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libidna-0edbd9fbe0e2018a.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libidna_adapter-d2c940c125ab7e8e.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libicu_normalizer-0d32ae24ea12272f.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libicu_normalizer_data-762e61f43eae08c2.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libwrite16-85fd16f27fd45657.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libutf8_iter-fbf995b92c341ba3.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libutf16_iter-83f8708e12b6535a.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libsmallvec-01f95b0ceff06af9.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libicu_properties-fc65325a720d86f3.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libicu_properties_data-52a01acc947e4a6d.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libicu_locid_transform-61fd28d8ec2573f3.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libicu_locid_transform_data-38f8208716c2d35a.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libicu_collections-52a62a3f145c76a6.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libicu_provider-40edb644d46dcbd8.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libicu_locid-df7637ee0726a00d.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/liblitemap-a0ca3b3971bb4be7.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libtinystr-9c4a0acb71aef736.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libzerovec-3dec1fdbced0d8d3.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libwriteable-c63e282ed55b92df.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libyoke-2ef6fd79cb3d7253.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libzerofrom-648302aad9f7e8fd.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libstable_deref_trait-3602560bab1848e8.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libform_urlencoded-38eafe171b6dc142.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libpercent_encoding-6b5d20e7e3073686.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libhttp-2ee8c6cbda2c6611.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libitoa-e8776415c5fe0047.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libfnv-b4bd047f342dff07.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libtime-93655dbd0c32143c.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libtime_core-920e11b901147e65.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libnum_conv-4bd030b5826783c5.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libderanged-e4c875d97de0e89c.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libpowerfmt-776ac6678c847955.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libbytes-4283fbd60d33408b.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libserde-84e90f1cae12c2c8.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libcxx_qt-dd29f9f5d1f05c43.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libstatic_assertions-3e50e277f96a204d.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libthiserror-97bff6de2a419edb.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libchrono-ba6303bd7b609f64.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libnum_traits-e0ed76299063a97d.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libiana_time_zone-327d1375b89fcc29.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libcxx-6360d2e1d0a105d3.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/libfoldhash-6366c6841c619481.rlib" \
    "/home/dev/git/leon-matthes-module-repro/target/debug/deps/liblink_cplusplus-a89f813d7bcd39db.rlib" \
    "/home/dev/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-ca74a2d9c5166d9f.rlib" \
    "/home/dev/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-e31ab23316ed5080.rlib" \
    "/home/dev/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-27dc4aa955912662.rlib" \
    "/home/dev/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libmemchr-bd0d6cccce077b99.rlib" \
    "/home/dev/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-8d001680935b5e3c.rlib" \
    "/home/dev/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-ba8ce71964f984f4.rlib" \
    "/home/dev/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-99a73526abcec14b.rlib" \
    "/home/dev/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-63ac0d22cff92579.rlib" \
    "/home/dev/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-9057355c92c922d5.rlib" \
    "/home/dev/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-358be9bc1f6bab04.rlib" \
    "/home/dev/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-aca15549d5bff974.rlib" \
    "/home/dev/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-8251d2cef7072448.rlib" \
    "/home/dev/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-7d50b86011c66411.rlib" \
    "/home/dev/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-51ea098fce5006bf.rlib" \
    "/home/dev/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-5a14e0d0b712e731.rlib" \
    "/home/dev/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-8b83dbf3a7b8f999.rlib" \
    "/home/dev/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-c6fd227bdc7b39ff.rlib" \
    "/home/dev/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-959d3389fa3da8a5.rlib" \
    "/home/dev/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-abe05db089cc2c62.rlib" \
    "-Wl,-Bdynamic" \
    "-lQt6QuickControls2" \
    "-lQt6Quick" \
    "-lQt6QmlMeta" \
    "-lQt6QmlWorkerScript" \
    "-lQt6QmlModels" \
    "-lQt6OpenGL" \
    "-lQt6Gui" \
    "-lGLX" \
    "-lOpenGL" \
    "-lQt6Qml" \
    "-lQt6Network" \
    "-lQt6Core" \
    "-lstdc++" \
    "-lQt6QuickControls2" \
    "-lQt6Quick" \
    "-lQt6QmlMeta" \
    "-lQt6QmlWorkerScript" \
    "-lQt6QmlModels" \
    "-lQt6OpenGL" \
    "-lQt6Gui" \
    "-lGLX" \
    "-lOpenGL" \
    "-lQt6Qml" \
    "-lQt6Network" \
    "-lQt6Core" \
    "-lstdc++" \
    "-lQt6Core" \
    "-lstdc++" \
    "-lstdc++" \
    "-lgcc_s" \
    "-lutil" \
    "-lrt" \
    "-lpthread" \
    "-lm" \
    "-ldl" \
    "-lc" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" \
    "-L" "/usr/lib" \
    "-L" "/home/dev/git/leon-matthes-module-repro/target/debug/build/cxx-401a9fca28d72681/out" \
    "-L" "/home/dev/git/leon-matthes-module-repro/target/debug/build/link-cplusplus-33eddc536860a848/out" \
    "-L" "/usr/lib" \
    "-L" "/usr/lib" \
    "-L" "/home/dev/git/leon-matthes-module-repro/target/debug/build/cxx-qt-23ee30d3ff19fb2e/out" \
    "-L" "/usr/lib" \
    "-L" "/home/dev/git/leon-matthes-module-repro/target/debug/build/cxx-qt-lib-198448e8be8ca490/out" \
    "-L" "/usr/lib" \
    "-L" "/home/dev/git/leon-matthes-module-repro/target/debug/build/qmlmod-55a1fb60efba77f9/out" \
    "-L" "/home/dev/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/dev/git/leon-matthes-module-repro/target/debug/deps/cxx_qt_module_repro-dbbbaf0ad2e1f035" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs" "-fuse-ld=gold" "/home/dev/git/leon-matthes-module-repro/target/debug/build/cxx-qt-module-repro-9d9e2e5aaf94f092/out/7ff832865d895eea-cxx-qt-module-repro.o" \
    = note: /home/dev/git/leon-matthes-module-repro/target/debug/build/cxx-qt-module-repro-9d9e2e5aaf94f092/out/cxx-qt-build/initializers/cxx-qt-module-repro.cpp:3: error: undefined reference to 'qt_static_plugin_CxxQt_Repro_plugin()'
          collect2: error: ld returned 1 exit status
          
  = note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-link-lib)

error: could not compile `cxx-qt-module-repro` (bin "cxx-qt-module-repro") due to 1 previous error

Here's a little debug info dump about my OS:

=== System Information ===
Linux thinkpadx1 6.12.4-arch1-1 #1 SMP PREEMPT_DYNAMIC Mon, 09 Dec 2024 14:31:57 +0000 x86_64 GNU/Linux

=== /etc/os-release ===
NAME="Arch Linux"
PRETTY_NAME="Arch Linux"
ID=arch
BUILD_ID=rolling

=== Environment Variables Related to Build Tools ===

=== Compiler Versions ===
--- cc ---
cc (GCC) 14.2.1 20240910

--- c++ ---
c++ (GCC) 14.2.1 20240910

--- clang ---
clang version 18.1.8
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

--- rustc ---
rustc 1.83.0 (90b35a623 2024-11-26)

--- cargo ---
cargo 1.83.0 (5ffbef321 2024-10-29)

=== Build System Tools ===
--- cmake ---
cmake version 3.31.2

CMake suite maintained and supported by Kitware (kitware.com/cmake).

--- qmake ---
QMake version 3.1
Using Qt version 6.8.1 in /usr/lib

Are you building on MacOS? Maybe the linker is less sensitive to the order of the object files?

@akiselev
Copy link
Contributor Author

akiselev commented Dec 18, 2024

Switching the linker to mold worked! I think the object files are being linked out of order and the default cc linker breaks.

For future reference, added this to the project .cargo/config.toml file:

[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = ["-C", "link-arg=-fuse-ld=/usr/bin/mold"]

@ahayzen-kdab
Copy link
Collaborator

Yeah the link order of ld.bfd has caused lots of problems vs ld.gold / lld / mold :-/ We managed to fix things for a CMake build to have the right order and in theory cc/cargo internal steps should be avoiding ld.bfd, so maybe this is a subtly different case to before 😅

@LeonMatthesKDAB
Copy link
Collaborator

Oh no, ld.bfd is at it again 🙈
I'm using mold as well, so didn't encounter that error...
(Can recommend using mold for everything anyway, it's way faster!)

@akiselev great that you figured out how to get it running, we can hopefully come up with a solution for 0.8 that doesn't have this issue.

@LeonMatthesKDAB
Copy link
Collaborator

@akiselev We now have a new PR that should fix this independent of the linker: #1178 🎉

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 🪲 bug Something isn't working 🔨 build system Issues related to integrating CXX-Qt into CMake/Cargo
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants