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

Link failure due to exporting function with a non-exported return type #27479

Closed
ghost opened this issue Aug 2, 2015 · 1 comment
Closed

Comments

@ghost
Copy link

ghost commented Aug 2, 2015

This code snippet causes a link failure. I am guessing it is because the return type of foo is not publicly exported from the crate it is causing a link failure in the test.

I tried this (reduced) code:

lib.rs

mod helper {
    pub struct Foo;
    impl Foo {
        pub fn baz(&self) { }
    }

    pub fn foo() -> Foo {
        return Foo;
    }
}

pub use helper::foo;

test.rs

extern crate lib;

#[test]
fn test() {
    lib::foo().baz();
}

I expected to see this happen: Definitely a clear error as opposed to a link failure. Probably an error stating that the return type of foo() is not visible outside the crate.

Instead, this happened: Linker error:

── env RUST_BACKTRACE=1 cargo test
   Compiling lib v0.1.0 (file:///Users/nwr/tmp/cargo-test/lib)
error: linking with `cc` failed: exit code: 1
note: "cc" "-m64" "-L" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib" "/Users/nwr/tmp/cargo-test/lib/target/debug/foo-5f1f39478ede92a5.0.o" "-o" "/Users/nwr/tmp/cargo-test/lib/target/debug/foo-5f1f39478ede92a5" "-Wl,-force_load,/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libmorestack.a" "-Wl,-dead_strip" "-nodefaultlibs" "/Users/nwr/tmp/cargo-test/lib/target/debug/liblib.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libtest-74fa456f.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libgetopts-74fa456f.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libserialize-74fa456f.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libterm-74fa456f.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/liblog-74fa456f.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libstd-74fa456f.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libcollections-74fa456f.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/librustc_unicode-74fa456f.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/librand-74fa456f.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/liballoc-74fa456f.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/liblibc-74fa456f.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libcore-74fa456f.rlib" "-L" "/Users/nwr/tmp/cargo-test/lib/target/debug" "-L" "/Users/nwr/tmp/cargo-test/lib/target/debug/deps" "-L" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib" "-L" "/Users/nwr/tmp/cargo-test/lib/.rust/lib/x86_64-apple-darwin" "-L" "/Users/nwr/tmp/cargo-test/lib/lib/x86_64-apple-darwin" "-l" "System" "-l" "pthread" "-l" "c" "-l" "m" "-l" "compiler-rt"
note: ld: warning: directory not found for option '-L/Users/nwr/tmp/cargo-test/lib/.rust/lib/x86_64-apple-darwin'
ld: warning: directory not found for option '-L/Users/nwr/tmp/cargo-test/lib/lib/x86_64-apple-darwin'
Undefined symbols for architecture x86_64:
  "helper::Foo::baz::heb3ebf21697cffffkaa", referenced from:
      test::h63ea6d9d3e0d725cfaa in foo-5f1f39478ede92a5.0.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 `lib`.

To learn more, run the command again with --verbose.

Meta

rustc --version --verbose (repos on 1.1.0 stable as well):

rustc 1.3.0-nightly (8ce69e856 2015-07-31)
binary: rustc
commit-hash: 8ce69e856a4def6ef39581823520c68944bd1c8e
commit-date: 2015-07-31
host: x86_64-apple-darwin
release: 1.3.0-nightly

Backtrace: None

@alexcrichton
Copy link
Member

Closing as a duplicate of #16734.

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

1 participant