Description
MWE (this does indeed require two separate crates and dynamic linking):
#### Workspace Cargo.toml
[workspace]
resolver = "2" # Important! wgpu/Bevy needs this!
members = ["cmp", "client"]
default-members = ["client"]
[workspace.package]
version = "0.1.0"
edition = "2021"
[profile.dev]
opt-level = 1
[profile.dev.package."*"]
opt-level = 3
#### cmp/Cargo.toml
[package]
name = "cmp"
edition.workspace = true
version.workspace = true
[lib]
crate-type = ["dylib"]
[dependencies]
bevy = { version = "0.14", features = ["dynamic_linking"] }
#### client/Cargo.toml
[package]
name = "client"
version.workspace = true
edition.workspace = true
[dependencies]
cmp = { path = "../cmp" }
//// client/src/main.rs (minimal bin stub)
fn main() {}
//// cmp/src/lib.rs
#![feature(trivial_bounds)]
use bevy::prelude::*;
#[derive(Reflect)]
pub struct MweReflected {
pub field: MweUnreflected,
}
pub struct MweUnreflected;
I expected to see this happen: The MweUnreflected
field does not implement Reflect
, which is a requirement of MweReflected
. Therefore, Rust should show an error relating to unsatisfied trait bounds, like what happens if you don't add #![feature(trivial_bounds)]
.
Instead, this happened: Reflect
has lots of generic implementations, including for lots of tuple types, and for some reason the compiler suggests to use #![feature(trivial_bounds)]
(That's the first error). When using this feature, instead of giving the same (or a better) error message, Rust instead causes a linker error, where the various Reflect
trait functions on MweUnreflected
cannot be found by link.exe.
Meta
rustc --version --verbose
:
rustc 1.82.0-nightly (612a33f20 2024-07-29)
binary: rustc
commit-hash: 612a33f20b9b2c27380edbc4b26a01433ed114bc
commit-date: 2024-07-29
host: x86_64-pc-windows-msvc
release: 1.82.0-nightly
LLVM version: 18.1.7
Linker errors
error: linking with `link.exe` failed: exit code: 1120
<long and sensitive linker invocation line omitted>
= note: lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp5model3nav1_108_$LT$impl$u20$bevy_reflect..type_registry..GetTypeRegistration$u20$for$u20$cmp..model..nav..NavComponent$GT$21get_type_registration17haeef134c9a08e10bE".␍
lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp5model3nav1_108_$LT$impl$u20$bevy_reflect..type_registry..GetTypeRegistration$u20$for$u20$cmp..model..nav..NavComponent$GT$26register_type_dependencies17hd5b05f4b2184b1feE".␍
lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp5model3nav1_90_$LT$impl$u20$bevy_reflect..reflect..Reflect$u20$for$u20$cmp..model..nav..NavComponent$GT$18reflect_partial_eq17h7193ed9efffbe4edE".␍
lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp5model3nav1_90_$LT$impl$u20$bevy_reflect..type_info..Typed$u20$for$u20$cmp..model..nav..NavComponent$GT$9type_info17h1383952cb944e417E".␍
lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp5model3nav1_94_$LT$impl$u20$bevy_reflect..struct_trait..Struct$u20$for$u20$cmp..model..nav..NavComponent$GT$11iter_fields17h374bad68a829126dE".␍
lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp5model3nav1_94_$LT$impl$u20$bevy_reflect..struct_trait..Struct$u20$for$u20$cmp..model..nav..NavComponent$GT$12field_at_mut17ha33376bd44e99291E".␍
lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp5model3nav1_94_$LT$impl$u20$bevy_reflect..struct_trait..Struct$u20$for$u20$cmp..model..nav..NavComponent$GT$13clone_dynamic17h76e402f00bd92585E".␍
lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp5model3nav1_94_$LT$impl$u20$bevy_reflect..struct_trait..Struct$u20$for$u20$cmp..model..nav..NavComponent$GT$5field17hcd641fb8c9a404e5E".␍
lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp5model3nav1_94_$LT$impl$u20$bevy_reflect..struct_trait..Struct$u20$for$u20$cmp..model..nav..NavComponent$GT$7name_at17h885325772a3bb243E".␍
lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp5model3nav1_94_$LT$impl$u20$bevy_reflect..struct_trait..Struct$u20$for$u20$cmp..model..nav..NavComponent$GT$8field_at17h8b4d6a71a905aafaE".␍
lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp5model3nav1_94_$LT$impl$u20$bevy_reflect..struct_trait..Struct$u20$for$u20$cmp..model..nav..NavComponent$GT$9field_len17hac564c17a54c82edE".␍
lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp5model3nav1_94_$LT$impl$u20$bevy_reflect..struct_trait..Struct$u20$for$u20$cmp..model..nav..NavComponent$GT$9field_mut17h014f952078d75a88E".␍
lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp5model3nav1_99_$LT$impl$u20$bevy_reflect..from_reflect..FromReflect$u20$for$u20$cmp..model..nav..NavComponent$GT$12from_reflect17h0317fca958b30622E".␍
lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp8graphics1_81_$LT$impl$u20$bevy_reflect..reflect..Reflect$u20$for$u20$cmp..graphics..Sides$GT$18reflect_partial_eq17h895ddd3c776b4042E".␍
lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp8graphics1_81_$LT$impl$u20$bevy_reflect..type_info..Typed$u20$for$u20$cmp..graphics..Sides$GT$9type_info17h2d4f02562378d1b3E".␍
lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp8graphics1_90_$LT$impl$u20$bevy_reflect..from_reflect..FromReflect$u20$for$u20$cmp..graphics..Sides$GT$12from_reflect17h8373a3f9dd382b4fE".␍
lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp8graphics1_90_$LT$impl$u20$bevy_reflect..tuple_struct..TupleStruct$u20$for$u20$cmp..graphics..Sides$GT$13clone_dynamic17h3353cfaa8143ce63E".␍
lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp8graphics1_90_$LT$impl$u20$bevy_reflect..tuple_struct..TupleStruct$u20$for$u20$cmp..graphics..Sides$GT$5field17h13206a0d6892ed5eE".␍
lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp8graphics1_90_$LT$impl$u20$bevy_reflect..tuple_struct..TupleStruct$u20$for$u20$cmp..graphics..Sides$GT$9field_mut17h14a60af13883f93cE".␍
lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp8graphics1_99_$LT$impl$u20$bevy_reflect..type_registry..GetTypeRegistration$u20$for$u20$cmp..graphics..Sides$GT$21get_type_registration17hdec5b11f70576bd1E".␍
lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp8graphics1_99_$LT$impl$u20$bevy_reflect..type_registry..GetTypeRegistration$u20$for$u20$cmp..graphics..Sides$GT$26register_type_dependencies17ha68b80319c65fe54E".␍
This issue was previously discussed here (the origin of the Reflect macro and trait). Related to #48214.