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

Linking error unless 'use'd #26872

Closed
TheNeikos opened this issue Jul 8, 2015 · 1 comment
Closed

Linking error unless 'use'd #26872

TheNeikos opened this issue Jul 8, 2015 · 1 comment

Comments

@TheNeikos
Copy link
Contributor

While working on a sample game with rust I encountered a strange bug which I believe to be a corner case of the setup I have. I am unable to recreate it in a simpler crate, so I am going to submit the code as I have it right now, hoping someone else might spot what is going wrong.

I have created a branch on my project that should reproduce this bug: https://github.com/TheNeikos/rpg/tree/error-linker

If you comment in line 13 in lib.rs it will compile.

Output of cargo run in that project:

neikos@celestias-palace ~/p/r/rpg> cargo run
   Compiling server v0.1.0 (file:///home/neikos/projects/rust/rpg)
<<<< Lots of warnings about unused stuff >>>>
error: linking with `cc` failed: exit code: 1
note: "cc" "-Wl,--as-needed" "-m64" "-L" "/usr/lib64/rustlib/x86_64-unknown-linux-gnu/lib" "/home/neikos/projects/rust/rpg/target/debug/rpg.o" "-o" "/home/neikos/projects/rust/rpg/target/debug/rpg" "-Wl,--whole-archive" "-l" "morestack" "-Wl,--no-whole-archive" "-Wl,--gc-sections" "-pie" "-nodefaultlibs" "/home/neikos/projects/rust/rpg/target/debug/deps/libserver-503340237efbae24.rlib" "/home/neikos/projects/rust/rpg/target/debug/deps/libshared-9e1f1e1585409fc5.rlib" "/home/neikos/projects/rust/rpg/target/debug/deps/libclock_ticks-995f487ba7426efb.rlib" "/home/neikos/projects/rust/rpg/target/debug/deps/liblibc-ef5cbad4ef5c7a1e.rlib" "/home/neikos/projects/rust/rpg/target/debug/deps/libbincode-1533ee1770371aad.rlib" "/home/neikos/projects/rust/rpg/target/debug/deps/librustc_serialize-c1e8163a38ed3d54.rlib" "/home/neikos/projects/rust/rpg/target/debug/deps/libbyteorder-399c175f6a7726ac.rlib" "/usr/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-74fa456f.rlib" "/usr/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcollections-74fa456f.rlib" "/usr/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_unicode-74fa456f.rlib" "/usr/lib/rustlib/x86_64-unknown-linux-gnu/lib/librand-74fa456f.rlib" "/usr/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-74fa456f.rlib" "/usr/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-74fa456f.rlib" "/usr/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-74fa456f.rlib" "-L" "/home/neikos/projects/rust/rpg/target/debug" "-L" "/home/neikos/projects/rust/rpg/target/debug/deps" "-L" "/usr/lib64/rustlib/x86_64-unknown-linux-gnu/lib" "-L" "/home/neikos/projects/rust/rpg/.rust/lib64/x86_64-unknown-linux-gnu" "-L" "/home/neikos/projects/rust/rpg/lib64/x86_64-unknown-linux-gnu" "-Wl,-Bstatic" "-Wl,-Bdynamic" "-l" "rt" "-l" "c" "-l" "m" "-l" "dl" "-l" "pthread" "-l" "rt" "-l" "gcc_s" "-l" "pthread" "-l" "c" "-l" "m" "-l" "compiler-rt"
note: /home/neikos/projects/rust/rpg/target/debug/rpg.o: In function `rpg::main':
/home/neikos/projects/rust/rpg/src/main.rs:42: undefined reference to `player::Player::get_id::hf61907f5ded04b74cfa'
collect2: error: ld returned 1 exit status

error: aborting due to previous error
Could not compile `rpg`.

To learn more, run the command again with --verbose.
neikos@celestias-palace ~/p/r/rpg> cargo -V
cargo 0.4.0-nightly (90422d6 2015-07-07) (built 2015-07-06)
neikos@celestias-palace ~/p/r/rpg> 

I think I am right to assume that rustc should error rather than the linker, as I found out the fix for this by random chance.

@alexcrichton
Copy link
Member

I believe that this is a dupe of #16734, so closing in favor of that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants