Linking problem

I am playing around with examples fro mthe ws websocket crate.

Every time I do a new build I have to run cargo clean first otherwise I get:

error: linking with `cc` failed: exit code: 1                                                                                 
|                       
  = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-Wl,--eh-frame-hdr" "-L" " <185 files>  "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-lutil"
 = note: collect2: error: ld returned 1 exit status

I find that a bit inscrutable.

Running with --verbose gives a bit of extra info at the end:

Caused by:                                                                                                                                                      
  process didn't exit successfully: `rustc --crate-name websock_01 --edition=2018 src/main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type \
bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=a57d56450b35a0c2 -C extra-filename=-a57d56450b35a0c2 --out-dir /home/patch/sandbox/webs\
ock_01/target/debug/deps -C incremental=/home/patch/sandbox/websock_01/target/debug/incremental -L dependency=/home/patch/sandbox/websock_01/target/debug/deps \
--extern env_logger=/home/patch/sandbox/websock_01/target/debug/deps/libenv_logger-707ba948eb1c7839.rlib --extern url=/home/patch/sandbox/websock_01/target/deb\
ug/deps/liburl-b48fd3b74faf0ba4.rlib --extern ws=/home/patch/sandbox/websock_01/target/debug/deps/libws-ef9f7e6572f6644a.rlib` (exit code: 1)       

I am stumped!

1 Like

Is there more to the error message than just "linking failed"? Normally the linker will spew out a bunch of "missing symbols" or "unable to find libfoo" messages before erroring out.

For example, with this dodgy code:

extern "C" {
    fn foo();
}

fn main() {
    unsafe { foo(); }
}

I get this error message:

$ rustc --version --verbose
rustc 1.53.0-nightly (361bfce30 2021-04-07)
binary: rustc
commit-hash: 361bfce305b8829eda7f3d133fe82a118685de1f
commit-date: 2021-04-07
host: x86_64-unknown-linux-gnu
release: 1.53.0-nightly
LLVM version: 12.0.0

$ rustc main.rs
error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-Wl,--eh-frame-hdr" "-L" "/home/michael/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "main.main.7rcbfp3g-cgu.0.rcgu.o" "main.main.7rcbfp3g-cgu.1.rcgu.o" "main.main.7rcbfp3g-cgu.2.rcgu.o" "-o" "main" "main.4s37gsrti678ik8u.rcgu.o" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-Wl,-O1" "-nodefaultlibs" "-L" "/home/michael/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,--start-group" "-Wl,-Bstatic" "/home/michael/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-b1047a2788193be4.rlib" "/home/michael/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-e8e399e2092f3b2a.rlib" "/home/michael/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-c6b02b522c91c060.rlib" "/home/michael/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-eaad965909c4200f.rlib" "/home/michael/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-dca728ac8ed54d87.rlib" "/home/michael/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-4b4efaa8c4601753.rlib" "/home/michael/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-d36e07ed2cc56ee4.rlib" "/home/michael/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-3855d04b1bb40ceb.rlib" "/home/michael/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-58a065cdff5508a2.rlib" "/home/michael/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-82aeeedcc8d1450a.rlib" "/home/michael/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-5c4d6c9d7595f844.rlib" "/home/michael/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-2642d2bccc00517a.rlib" "/home/michael/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-760e48b3f782e7f5.rlib" "/home/michael/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-d4ef8bf89076ed01.rlib" "/home/michael/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-36070e2029bb21ea.rlib" "/home/michael/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-3aaf8f932781f33e.rlib" "-Wl,--end-group" "/home/michael/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-e2523c360f03ba10.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc"
  = note: /usr/bin/ld: main.main.7rcbfp3g-cgu.0.rcgu.o: in function `main::main':
          main.7rcbfp3g-cgu.0:(.text._ZN4main4main17h2d6c3d678af9e020E+0x2): undefined reference to `foo'
          collect2: error: ld returned 1 exit status

Where the second note explains exactly what went wrong (main::main() used the foo symbol which can't be found).

It sounds like there may be an issue with incremental compilation. Which version of the compiler are you using?

rustc --version
rustc 1.50.0 (cb75ad5db 2021-02-10)

I ran out of disc!

Feeling a bit silly here. Thank you for your attention tho

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.