Undefined reference to rust_metadata_*


Trying to use a privately built toolchain (and the same issue does not repro using the upstream toolchain), specifically 1.72.0.

When I try to test (cargo test -p xxx) my library that has proc-macro = true in its Cargo.toml, the linker fails with the following issue:

error: linking with `cc` failed: exit status: 1
  = note: /usr/bin/ld: /usr/lib64/rustlib/x86_64-unknown-linux-gnu/lib/libtest-d6d9932403ef26ef.so: undefined reference to `rust_metadata_test_a1fb1c9aa77ad7cd'
          /usr/bin/ld: /usr/lib64/rustlib/x86_64-unknown-linux-gnu/lib/libstd-7adc38a616225c50.so: undefined reference to `rust_metadata_std_7e896df83ed4f19'
          collect2: error: ld returned 1 exit status
  = note: 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)

error: could not compile `xxx` (lib test) due to previous error

Do you have any pointers what could be missing/misconfigured in my toolchain in a way that would result in this issue?


I test if I have cc or ldd installed by entering those commands in a shell and inspecting the output. It may be that choosing the right local install is all that's needed for -l.

For cargo the linker may be defined here: Configuration - The Cargo Book, there are many examples of doing this in various Github repositories found with an appropriate search string.

Further information on the same topic is found here: GitHub - japaric/rust-cross: Everything you need to know about cross compiling Rust programs!.

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.