Skip to content

Commit 287d484

Browse files
committed
nixos: cargo linker error
1 parent 575de14 commit 287d484

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
title: "NixOS: cargo linker error"
3+
categories:
4+
- linux
5+
- nixos
6+
- rust
7+
---
8+
9+
There are multiple ways to install a rust toolchain under NixOS.
10+
One easy way is to install `gcc, rustup` system-wide, e.g.
11+
```nixos
12+
# file: /etc/nixos/configuration.nix:
13+
environment.systemPackages = with pkgs; [
14+
rustup
15+
gcc
16+
];
17+
```
18+
19+
This setup might brake after updating NixOS (and removing older generations) as this will delete files from /nix/store/ and cargo might still use stale paths (e.g. for the linker).
20+
21+
Example error message:
22+
```bash
23+
$ cargo run --bin ex-5-1-simple-mutex-based-channel
24+
Compiling rust-atomics-mara-bos v0.1.0 (/home/paul/info/rust/rust-atomics-mara-bos)
25+
error: linking with `cc` failed: exit status: 1
26+
|
27+
= note: "cc" "-m64" "/tmp/rustcnDnLRB/symbols.o" "<50 object files omitted>" "-Wl,--as-needed" "-Wl,-Bstatic" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib/{libstd-*,libpanic_unwind-*,libobject-*,libmemchr-*,libaddr2line-*,libgimli-*,librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libminiz_oxide-*,libadler2-*,libunwind-*,libcfg_if-*,liblibc-*,librustc_std_workspace_core-*,liballoc-*,libcore-*,libcompiler_builtins-*}.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-L" "/tmp/rustcnDnLRB/raw-dylibs" "-B<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/bin/gcc-ld" "-fuse-ld=lld" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/paul/info/rust/rust-atomics-mara-bos/target/debug/deps/ex_5_1_simple_mutex_based_channel-4e487e50b234f6fd" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs"
28+
= note: some arguments are omitted. use `--verbose` to show all linker arguments
29+
= note: /home/paul/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/gcc-ld/ld.lld: line 5: /nix/store/pwrvyffzg8hzvi4d864q8bmjr7vfaxqz-rustup-1.27.1/nix-support/ld-wrapper.sh: No such file or directory
30+
collect2: error: ld returned 127 exit status
31+
32+
error: could not compile `rust-atomics-mara-bos` (bin "ex-5-1-simple-mutex-based-channel") due to 1 previous error
33+
```
34+
35+
This can be fixed via
36+
```bash
37+
$ rustup toolchain remove stable
38+
$ rustup toolchain install stable
39+
```

0 commit comments

Comments
 (0)