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

Subcrate's privates leak, and then cause linker errors #1690

Closed
bfops opened this issue Jun 7, 2015 · 2 comments
Closed

Subcrate's privates leak, and then cause linker errors #1690

bfops opened this issue Jun 7, 2015 · 2 comments

Comments

@bfops
Copy link

bfops commented Jun 7, 2015

I'm getting a parent crate to "accidentally" use private functions from a sub-crate private module. The compile succeeds, but then the link fails!

main.rs:

extern crate bar;

fn main() {
  let bar = bar::Bar::new();
  bar.foo.foo();
}

bar/mod.rs

mod priv_bar;

pub struct Bar {
  pub foo: priv_bar::Foo,
}

impl Bar {
  pub fn new() -> Bar {
    Bar { foo: priv_bar::Foo }
  }
}

bar/priv_bar.rs:

pub struct Foo;

impl Foo {
  pub fn foo(&self) {
    println!("hello world");
  }
}

If bar/priv_bar.rs is inlined into bar/mod.rs, this doesn't happen; the correct error message is printed.

@bfops
Copy link
Author

bfops commented Jun 7, 2015

  Compiling bar v0.0.0 (file:///home/ben/sync/devl/test)
bar/priv_bar.rs:4:3: 6:4 warning: method is never used: `foo`, #[warn(dead_code)] on by default
bar/priv_bar.rs:4   pub fn foo(&self) {
bar/priv_bar.rs:5     println!("hello world");
bar/priv_bar.rs:6   }
  Compiling foo v0.0.0 (file:///home/ben/sync/devl/test)
error: linking with `cc` failed: exit code: 1
note: "cc" "-Wl,--as-needed" "-m64" "-L" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/home/ben/sync/devl/test/target/debug/foo.o" "-o" "/home/ben/sync/devl/test/target/debug/foo" "-Wl,--whole-archive" "-l" "morestack" "-Wl,--no-whole-archive" "-Wl,--gc-sections" "-pie" "-nodefaultlibs" "/home/ben/sync/devl/test/target/debug/deps/libbar-969d3503f37f9633.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-11582ce5.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcollections-11582ce5.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_unicode-11582ce5.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/librand-11582ce5.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-11582ce5.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-11582ce5.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-11582ce5.rlib" "-L" "/home/ben/sync/devl/test/target/debug" "-L" "/home/ben/sync/devl/test/target/debug/deps" "-L" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-L" "/home/ben/sync/devl/test/.rust/lib/x86_64-unknown-linux-gnu" "-L" "/home/ben/sync/devl/test/lib/x86_64-unknown-linux-gnu" "-Wl,-Bstatic" "-Wl,-Bdynamic" "-l" "dl" "-l" "pthread" "-l" "rt" "-l" "gcc_s" "-l" "pthread" "-l" "c" "-l" "m" "-l" "compiler-rt"
note: /home/ben/sync/devl/test/target/debug/foo.o: In function `foo::main':
/home/ben/sync/devl/test/main.rs:5: undefined reference to `priv_bar::Foo::foo::ha1d68178bb28c0bckaa'
collect2: error: ld returned 1 exit status

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

@alexcrichton
Copy link
Member

I believe this is a dupe of rust-lang/rust#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