3
votes

I installed Rust using the instructions in the documentation on my Debian 9.2 system and tried to compile the hello world example. The compilation failed with the following error:

$ rustc main.rs --verbose
error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/frederick/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "main.main0.rust-cgu.o" "main.main1.rust-cgu.o" "-o" "main" "main.crate.allocator.rust-cgu.o" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs" "-L" "/home/frederick/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/home/frederick/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-fe0b1b991511fcaa.rlib" "/home/frederick/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librand-3d7b10e850a67e89.rlib" "/home/frederick/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-28484309357fd6f1.rlib" "/home/frederick/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_system-751808ba756769d5.rlib" "/home/frederick/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-8cb97051d8238386.rlib" "/home/frederick/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-25cc9b024a02d330.rlib" "/home/frederick/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-d42e80cee81b06ce.rlib" "/home/frederick/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-78c21267a2dc15c1.rlib" "/home/frederick/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_unicode-0e1b544c94586415.rlib" "/home/frederick/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-0c5e3d6c117f8c44.rlib" "/home/frederick/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-bd7cc5ada1e908e0.rlib" "-Wl,-Bdynamic" "-l" "dl" "-l" "rt" "-l" "pthread" "-l" "pthread" "-l" "gcc_s" "-l" "c" "-l" "m" "-l" "rt" "-l" "pthread" "-l" "util"
  = note: ld-wrapper: error: attempt to use impure library "/usr/lib/gcc/x86_64-linux-gnu/6/libgcc_s.so"
          collect2: error: ld returned 1 exit status

The following is the output of running uname -a on my system

Linux localhost 4.9.0-4-amd64 #1 SMP Debian 4.9.51-1 (2017-09-28) x86_64 GNU/Linux

I tried the following searches on google, but cannot seem to find anything useful:

  • rustc AND ld-wrapper: error: attempt to use impure library
  • rustc AND ld-wrapper: error: attempt to use impure library "/usr/lib/gcc/x86_64-linux-gnu/6/libgcc_s.so"
  • rustc AND error: linking with cc failed: exit code: 1
1
There's the kernel, and there's the packages / libraries offered by a distro. I was going off of lsb_release -a reporting Description: Debian GNU/Linux 9.3 (stretch). It could be as simple as their install script looking for hardcoded strings like "ubuntu" and not "debian". If you poke around perhaps you'll create a helpful patch.J_H
Eventually, I unistalled the system rustc and installed rustc via GNU Guix, but that is a convoluted process for most people. I did report the bug so hopefully that gets fixedfredmanglis

1 Answers

0
votes

Debian 9.3 is current, but that probably matters much less than Debian being tested less than Ubuntu.

On Ubuntu Xenial the install / compile directions worked fine for me.

You seem to be bumping into a not-well-documented corner case, where a pair of references are relevant:

https://www.mail-archive.com/[email protected]/msg34510.html

... attempt to use impure library, error message

The wrapper's purpose is to inspect the @code{-L} and @code{-l} switches passed to the linker, add corresponding @code{-rpath} arguments, and invoke the actual linker with this new set of arguments. By default, the linker wrapper refuses to link to libraries outside the store to ensure ``purity''. This can be annoying when using the toolchain to link with local libraries. To allow references to libraries outside the store you need to define the environment variable @code{GUIX_LD_WRAPPER_ALLOW_IMPURITIES}.

And this bit of code:

https://lists.gnu.org/archive/html/help-guix/2016-12/msg00040.html

... for future reference, to hack on a haskell package these are the steps:

... export GUIX_LD_WRAPPER_ALLOW_IMPURITIES=y ...

If GUIX is even relevant to your situation, then defining that may let you get a bit further in the install process.