Cargo "linking with cc failed" only when building tests

Hello, I have yesterday ran into this linker issue when executing cargo test, but not cargo build.

error: linking with `cc` failed: exit status: 1
  |
 (...)
  = note: /home/.../code/.../production/device/APU/target/debug/deps/event_publisher_macro-067da5dc8c3e3607.dboylq6anpojh5z.rcgu.o: In function `<T as core::convert::Into<U>>::into':
          /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/core/src/convert/mod.rs:540: undefined reference to `<T as core::convert::From<T>>::from'
          collect2: error: ld returned 1 exit status
          
  = help: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)

I have never seen this issue before and I did not add or remove any libraries. The error message is telling me that it can't link against core library conversion functions. What is happening here?

2 Likes

It seems like your copy of the standard library is corrupted in some way. You could try to reinstall your toolchain to get new copies of the Rust compiler and compiled binaries for the standard library. For stable you might run something like rustup toolchain uninstall stable && rustup toolchain install stable.

This is very strange though and not normal. You might want to create a ticket against the rustup repo because there may be a bug in the way the toolchain are distributed or installed.

3 Likes

Thank you. My problem seems to be solved by switching it off and on again... :slight_smile:

I can surely open an issue in the rustup repo, but there's so little info I can provide to reproduce the problem that I am wondering if it even makes sense. What do you think?

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.