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

Missing Reflect on a child leads to linker errors on Windows #14607

Closed
kleinesfilmroellchen opened this issue Aug 3, 2024 · 7 comments
Closed
Labels
A-Reflection Runtime information about types C-Bug An unexpected or incorrect behavior S-Needs-Investigation This issue requires detective work to figure out what's going wrong

Comments

@kleinesfilmroellchen
Copy link

Bevy version

0.14

What you did

I used #[derive(Reflect)] on several components that were missing a Reflect implementation on a child type. While this is of course not possible, I would expect a nicer error message than some linker errors that had me searching for about half an hour.

What went wrong

The build fails with linker errors like this one:

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".␍

Additional information

In my case, Sides is the type that doesn't have Reflect, and NavComponent is a struct with a Sides field, but NavComponent itself has a Reflect derive.

@kleinesfilmroellchen kleinesfilmroellchen added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Aug 3, 2024
@MrGVSV MrGVSV added A-Reflection Runtime information about types S-Needs-Investigation This issue requires detective work to figure out what's going wrong and removed S-Needs-Triage This issue needs to be labelled labels Aug 4, 2024
@MrGVSV
Copy link
Member

MrGVSV commented Aug 4, 2024

Could you provide a minimum reproducible example of the code that causes this, as well as steps to reproduce the error?

And just to confirm, is this being built on Windows? lol I didn't fully read the title apparently

@kleinesfilmroellchen
Copy link
Author

Currently working on that MWE with slow progress. I'm fairly confident this is related to my linking setup: The crate that contains the Reflect-ed structs is dynamically linked into the executable. (If I put the structs into the executable's own crate, I get a normal error)

@kleinesfilmroellchen
Copy link
Author

MWE coming in a bit, but it seems to be related to the following:

  • #![feature(trivial_bounds)] (which the Rust compiler recommends you to use when it detects that Reflect trait bounds are not satisfied)
  • (possibly relevant) rustc 1.82.0-nightly (612a33f20 2024-07-29)
  • the crate with both the feature and the problematic reflected structs is a lib crate that is dynamically linked into a bin crate

So this might not be worth investigating right now, given that it depends on unstable Rust features to happen.

@kleinesfilmroellchen
Copy link
Author

kleinesfilmroellchen commented Aug 4, 2024

MWE:

#### 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;

@soqb
Copy link
Contributor

soqb commented Aug 4, 2024

this looks like a plain mistake on Rust's behalf. !#[feature(trivial_bounds)] is an incorrect suggestion here and that's what's causing the linker errors.

@kleinesfilmroellchen
Copy link
Author

@soqb this means the problem is twofold:

  • trivial_bounds has a bug where it may cause linker errors by not emitting certain symbols (or something similar)
  • the compiler's suggestion to use the trivial_bounds feature is imprecise

I'll report this on rust-lang/rust then.

@kleinesfilmroellchen
Copy link
Author

Moved to rust-lang/rust#128682

@kleinesfilmroellchen kleinesfilmroellchen closed this as not planned Won't fix, can't repro, duplicate, stale Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Reflection Runtime information about types C-Bug An unexpected or incorrect behavior S-Needs-Investigation This issue requires detective work to figure out what's going wrong
Projects
None yet
Development

No branches or pull requests

3 participants