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

ld: archive has no table of contents file #18650

Closed
benanders opened this issue Nov 5, 2014 · 6 comments
Closed

ld: archive has no table of contents file #18650

benanders opened this issue Nov 5, 2014 · 6 comments

Comments

@benanders
Copy link

Hi, I'm trying to make a really really simple hello world program in Rust using a custom library through Cargo, and I'm getting the error:

   Compiling rstestlib v0.0.1 (file:///Users/benanderson/Desktop/rstest)
   Compiling rstest v0.0.1 (file:///Users/benanderson/Desktop/rstest)
error: linking with `cc` failed: exit code: 1
note: cc '-m64' '-L' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib' '-o' '/Users/benanderson/Desktop/rstest/target/rstest' '/Users/benanderson/Desktop/rstest/target/rstest.o' '-Wl,-force_load,/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libmorestack.a' '-nodefaultlibs' '-fno-lto' '-Wl,-dead_strip' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libnative-4e7c5e5c.rlib' '/Users/benanderson/Desktop/rstest/target/deps/librstestlib-1806f5315b450877.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libstd-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/librand-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libsync-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/librustrt-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/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/benanderson/Desktop/rstest/target' '-L' '/Users/benanderson/Desktop/rstest/target/deps' '-L' '/Users/benanderson/Desktop/rstest/.rust' '-L' '/Users/benanderson/Desktop/rstest' '-lSystem' '-lpthread' '-lc' '-lm' '-lcompiler-rt'
note: ld: warning: directory not found for option '-L/Users/benanderson/Desktop/rstest/.rust'
ld: archive has no table of contents file '/Users/benanderson/Desktop/rstest/target/deps/librstestlib-1806f5315b450877.rlib' 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 `rstest`.

I have a lib rstestlib, containing a lib.rs with this inside it:

pub fn test() {
    println!("Test");
}

And the rstest program has a main.rs with:

extern crate rstestlib;
fn main() {
    rstestlib::test();
}

The rstest program has this as a Cargo.toml file:

[package]
name = "rstest"
version = "0.0.1"
authors = ["GravityScore <[email protected]>"]

[dependencies.rstestlib]
path = "../rstestlib"

And the rstestlib program has this as a Cargo.toml:

[package]
name = "rstestlib"
version = "0.0.1"
authors = ["GravityScore <[email protected]>"]

I've just reinstalled rust using the 1 line console command from the Cargo website. The output of rustc -v is rustc 0.13.0-nightly (0a5e7f359 2014-11-03 23:16:55 +0000). I've had this problem for a while now, and it's really disappointing because I love rust so much, but I can't use it at all anymore.

I've tried running ranlib target/deps/librstestlib* as some internet sources (eg. here) suggest, but when I do this I get a bunch of undefined symbols for architecture, and a note saying the .rlib file was not built for the current architecture I'm trying to build for (which is x86_64):

Bens-MacBook-Pro-4:rstest benanderson$ ranlib target/deps/librstestlib*
Bens-MacBook-Pro-4:rstest benanderson$ cargo build
   Compiling rstest v0.0.1 (file:///Users/benanderson/Desktop/rstest)
error: linking with `cc` failed: exit code: 1
note: cc '-m64' '-L' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib' '-o' '/Users/benanderson/Desktop/rstest/target/rstest' '/Users/benanderson/Desktop/rstest/target/rstest.o' '-Wl,-force_load,/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libmorestack.a' '-nodefaultlibs' '-fno-lto' '-Wl,-dead_strip' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libnative-4e7c5e5c.rlib' '/Users/benanderson/Desktop/rstest/target/deps/librstestlib-1806f5315b450877.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libstd-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libsync-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/librustrt-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/liballoc-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/liblibc-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/librand-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libcore-4e7c5e5c.rlib' '-L' '/Users/benanderson/Desktop/rstest/target' '-L' '/Users/benanderson/Desktop/rstest/target/deps' '-L' '/Users/benanderson/Desktop/rstest/.rust' '-L' '/Users/benanderson/Desktop/rstest' '-lSystem' '-lpthread' '-lc' '-lm' '-lcompiler-rt'
note: ld: warning: directory not found for option '-L/Users/benanderson/Desktop/rstest/.rust'

ld: warning: ignoring file /Users/benanderson/Desktop/rstest/target/deps/librstestlib-1806f5315b450877.rlib, file was built for archive which is not the architecture being linked (x86_64): /Users/benanderson/Desktop/rstest/target/deps/librstestlib-1806f5315b450877.rlib

Undefined symbols for architecture x86_64:
  "test::hb3734900dfb5a78ddaa", referenced from:
      main::h7d8e0789b2179c99faa in rstest.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 `rstest`.

But, if I run lipo -info target/deps/librstestlib*, it says the archive file was built for x86_64:

input file target/deps/librstestlib-1806f5315b450877.rlib is not a fat file
Non-fat file: target/deps/librstestlib-1806f5315b450877.rlib is architecture: x86_64

This happens with any library I try and link, ones from GitHub or locally. I'm running OSX Yosemite (10.10), with the latest Xcode (6.1) and OSX SDKs installed. I get the same problem if I bypass Cargo and compile using rustc directly as well, so it's not a Cargo problem. I used the command rustc -L"../rstestlib/target" src/main.rs.

Does someone know what's going on here? I'm really stuck and can't figure out why this is happening. I really love Rust and really appreciate all the hard work that's gone into making it - it is fantastic. But it's not working at the moment, which is really disappointing and very limiting if I can't link against libraries.

@alexcrichton
Copy link
Member

Hm, this seems odd. To get a handle on what's going on here, could you try compiling with rustc manually instead of using cargo? (would also help minimize). Something like this should do the trick:

$ rustc rstestlib/src/lib.rs --crate-name rstestlib --crate-type rlib
$ rustc rstest/src/lib.rs -L .

@benanders
Copy link
Author

Unfortunately that still fails. Here's the exact output:

error: linking with `cc` failed: exit code: 1
note: cc '-m64' '-L' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib' '-o' 'rstest' 'rstest.o' '-Wl,-force_load,/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libmorestack.a' '-nodefaultlibs' '-fno-lto' '-Wl,-dead_strip' '/Users/benanderson/Desktop/rstest/librstestlib.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libnative-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libstd-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/librand-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libsync-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/librustrt-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/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' '.' '-L' '/Users/benanderson/Desktop/rstest/.rust' '-L' '/Users/benanderson/Desktop/rstest' '-lSystem' '-lpthread' '-lc' '-lm' '-lcompiler-rt'
note: ld: warning: directory not found for option '-L/Users/benanderson/Desktop/rstest/.rust'
ld: archive has no table of contents file '/Users/benanderson/Desktop/rstest/librstestlib.rlib' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

error: aborting due to previous error

@benanders
Copy link
Author

So I came across this: tpoechtrager/osxcross#11 which is someone having the exact same problem for something else, mentioning that the default archiver isn't sufficient and that x86_64-apple-darwin1X-ar needs to be used. I'm not entirely sure what this means, but does this help in any way?

@benanders
Copy link
Author

I just tried to build Rust from the source, and I also get a bunch of file was built for archive which is not the architecture being linked errors:

ld: warning: ignoring file /Users/benanderson/Desktop/test/rust/x86_64-apple-darwin/llvm/Release+Asserts/lib/libLLVMBitWriter.a, file was built for archive which is not the architecture being linked (x86_64): /Users/benanderson/Desktop/test/rust/x86_64-apple-darwin/llvm/Release+Asserts/lib/libLLVMBitWriter.a
ld: warning: ignoring file /Users/benanderson/Desktop/test/rust/x86_64-apple-darwin/llvm/Release+Asserts/lib/libLLVMipo.a, file was built for archive which is not the architecture being linked (x86_64): /Users/benanderson/Desktop/test/rust/x86_64-apple-darwin/llvm/Release+Asserts/lib/libLLVMipo.a
ld: warning: ignoring file /Users/benanderson/Desktop/test/rust/x86_64-apple-darwin/llvm/Release+Asserts/lib/libLLVMProfileData.a, file was built for archive which is not the architecture being linked (x86_64): /Users/benanderson/Desktop/test/rust/x86_64-apple-darwin/llvm/Release+Asserts/lib/libLLVMProfileData.a
ld: warning: ignoring file /Users/benanderson/Desktop/test/rust/x86_64-apple-darwin/llvm/Release+Asserts/lib/libLLVMBitReader.a, file was built for archive which is not the architecture being linked (x86_64): /Users/benanderson/Desktop/test/rust/x86_64-apple-darwin/llvm/Release+Asserts/lib/libLLVMBitReader.a
ld: warning: ignoring file /Users/benanderson/Desktop/test/rust/x86_64-apple-darwin/llvm/Release+Asserts/lib/libLLVMInstCombine.a, file was built for archive which is not the architecture being linked (x86_64): /Users/benanderson/Desktop/test/rust/x86_64-apple-darwin/llvm/Release+Asserts/lib/libLLVMInstCombine.a
ld: warning: ignoring file /Users/benanderson/Desktop/test/rust/x86_64-apple-darwin/llvm/Release+Asserts/lib/libLLVMAnalysis.a, file was built for archive which is not the architecture being linked (x86_64): /Users/benanderson/Desktop/test/rust/x86_64-apple-darwin/llvm/Release+Asserts/lib/libLLVMAnalysis.a
ld: warning: ignoring file /Users/benanderson/Desktop/test/rust/x86_64-apple-darwin/llvm/Release+Asserts/lib/libLLVMMC.a, file was built for archive which is not the architecture being linked (x86_64): /Users/benanderson/Desktop/test/rust/x86_64-apple-darwin/llvm/Release+Asserts/lib/libLLVMMC.a

Is this best off in a separate issue?

@benanders
Copy link
Author

More info from the latest rust version:

ld: archive has no table of contents file '/Users/benanderson/workspace/rust/test/target/deps/libtestlib-79bbf85880b0bfea.rlib' for architecture x86_64
0  0x10573ab51  __assert_rtn + 144
1  0x10578b8ce  ld::tool::InputFiles::waitForInputFiles() + 0
2  0x7fff894ee2fc  _pthread_body + 131
3  0x7fff894ee279  _pthread_body + 0
A linker snapshot was created at:
    (null)
ld: Assertion failed: (slot < (int)files.size()), function parseWorkerThread, file /SourceCache/ld64/ld64-241.9/src/ld/InputFiles.cpp, line 920.
clang: error: linker command failed with exit code 1 (use -v to see invocation)

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

I also just downloaded Rust 0.12 rather than the latest nightly, and I get the same error, so it's something environmental causing it, not Rust itself. Any ideas anyone? I'm a bit desparate now.

@benanders
Copy link
Author

So this turns out to be a completely environmental issue. There were a bunch of duplicate files of system programs (like ls, mv, etc...). Removing them got rust to work again!

lnicola added a commit to lnicola/rust that referenced this issue Dec 11, 2024
crates/r-a: Fix typo in debug message
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