My Rust compiler version is:
$ rustc --version
rustc 1.0.0-nightly (3e4be02b8 2015-03-13) (built 2015-03-13)
My Cargo version is:
$ cargo --version
cargo 0.0.1-pre-nightly (66849de 2015-03-10) (built 2015-03-11)
I was happily coding my rust project when I got this compilation error:
$ cargo build --verbose
Fresh log v0.2.5
Fresh rustc-serialize v0.3.6
Fresh libc v0.1.3
Fresh rand v0.1.4
Fresh uuid v0.1.11
Compiling rexchange v0.0.1 (file:///Users/sam/dev/rexchange)
Running `rustc src/main.rs --crate-name rexchange --crate-type bin -g --out-dir /Users/sam/dev/rexchange/target/debug --emit=dep-info,link -L dependency=/Users/sam/dev/rexchange/target/debug -L dependency=/Users/sam/dev/rexchange/target/debug/deps --extern uuid=/Users/sam/dev/rexchange/target/debug/deps/libuuid-f80da2be6e37bdc9.rlib --extern rexchange=/Users/sam/dev/rexchange/target/debug/librexchange-436e10ddf2e26a6f.rlib`
error: linking with `cc` failed: exit code: 1
note: "cc" "-m64" "-L" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib" "-o" "/Users/sam/dev/rexchange/target/debug/rexchange" "/Users/sam/dev/rexchange/target/debug/rexchange.o" "-Wl,-force_load,/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libmorestack.a" "-Wl,-dead_strip" "-nodefaultlibs" "/Users/sam/dev/rexchange/target/debug/librexchange-436e10ddf2e26a6f.rlib" "/Users/sam/dev/rexchange/target/debug/deps/libuuid-f80da2be6e37bdc9.rlib" "/Users/sam/dev/rexchange/target/debug/deps/librustc-serialize-6bb45c0d7c639d54.rlib" "/Users/sam/dev/rexchange/target/debug/deps/librand-6dfe5258ada5ebf2.rlib" "/Users/sam/dev/rexchange/target/debug/deps/liblibc-2a692f33a70517c8.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libstd-4e7c5e5c.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libcollections-4e7c5e5c.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libunicode-4e7c5e5c.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/librand-4e7c5e5c.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/liballoc-4e7c5e5c.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/liblibc-4e7c5e5c.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libcore-4e7c5e5c.rlib" "-L" "/Users/sam/dev/rexchange/target/debug" "-L" "/Users/sam/dev/rexchange/target/debug/deps" "-L" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib" "-L" "/Users/sam/dev/rexchange/.rust/lib/x86_64-apple-darwin" "-L" "/Users/sam/dev/rexchange/lib/x86_64-apple-darwin" "-lc" "-lm" "-lSystem" "-lpthread" "-lc" "-lm" "-lcompiler-rt"
note: ld: warning: directory not found for option '-L/Users/sam/dev/rexchange/.rust/lib/x86_64-apple-darwin'
ld: warning: directory not found for option '-L/Users/sam/dev/rexchange/lib/x86_64-apple-darwin'
Undefined symbols for architecture x86_64:
"orders::BidOrder::get_account_id::hbe8193f627eb0daf4ba", referenced from:
main::h6e33cd0005718795haa in rexchange.o
"orders::BidOrder::get_currency_price::hac0a15cbc8d29001Gba", referenced from:
main::h6e33cd0005718795haa in rexchange.o
"orders::BidOrder::get_commodity_amount::hce97000d2a1749beSba", referenced from:
main::h6e33cd0005718795haa in rexchange.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: aborting due to previous error
Could not compile `rexchange`.
Caused by:
Process didn't exit successfully: `rustc src/main.rs --crate-name rexchange --crate-type bin -g --out-dir /Users/sam/dev/rexchange/target/debug --emit=dep-info,link -L dependency=/Users/sam/dev/rexchange/target/debug -L dependency=/Users/sam/dev/rexchange/target/debug/deps --extern uuid=/Users/sam/dev/rexchange/target/debug/deps/libuuid-f80da2be6e37bdc9.rlib --extern rexchange=/Users/sam/dev/rexchange/target/debug/librexchange-4
I've no idea why this failure occurred and I couldn't find anything that looked similar. Can anyone explain to me what is going on and how to fix?
The code is: https://github.com/samphippen/rexchange
I can reproduce the issue, and have a workaround. I'm not sure if it's a Rust bug or not, but it's certainly surprising, so I'd encourage you to file it (or let me know and I can do it).
First, I created a new cargo project called repro
. I then added these files:
lib.rs
mod order {
pub struct Alpha(pub u8);
impl Alpha {
pub fn value(&self) -> u8 { self.0 }
}
}
pub mod interface {
use super::order::Alpha;
pub fn yeah() -> Alpha { Alpha(8) }
}
main.rs
extern crate repro;
fn main() {
println!("{:?}", repro::interface::yeah().value());
}
During compilation, this warning is generated:
src/lib.rs:5:9: 5:45 warning: method is never used: `value`, #[warn(dead_code)] on by default
src/lib.rs:5 pub fn value(&self) -> u8 { self.0 }
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Which is surprising, as we indeed use it in main
. Compilation then fails with the same linking error you saw.
The workaround is to mark the order
module as public:
pub mod order {
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With