0

I was trying to build c++ code inside rust, and somehow I made some changes and now I am not even able to do simple cargo build command as it's providing me the following error

error: could not compile `io-lifetimes` (build script) due to previous error
error: linking with `cc` failed: exit status: 1

= note: LC_ALL="C" PATH="/home/akumar/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/opt/ros/noetic/bin:/home/akumar/.cargo/bin:/opt/gcc-arm-none-eabi-9-2020-q2-update/bin:/home/akumar/.local/bin:/opt/spinnaker/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin" VSLANG="1033" "cc" "-m64" "/tmp/rustcIAS5Hk/symbols.o" "/home/akumar/test/abc/target/release/build/typenum-e6331931ff63e8b8/build_script_main-e6331931ff63e8b8.build_script_main.8bfffe8e-cgu.0.rcgu.o" "/home/akumar/test/abc/target/release/build/typenum-e6331931ff63e8b8/build_script_main-e6331931ff63e8b8.build_script_main.8bfffe8e-cgu.1.rcgu.o" "/home/akumar/test/abc/target/release/build/typenum-e6331931ff63e8b8/build_script_main-e6331931ff63e8b8.build_script_main.8bfffe8e-cgu.10.rcgu.o" "/home/akumar/test/abc/target/release/build/typenum-e6331931ff63e8b8/build_script_main-e6331931ff63e8b8.build_script_main.8bfffe8e-cgu.11.rcgu.o" "/home/akumar/test/abc/target/release/build/typenum-e6331931ff63e8b8/build_script_main-e6331931ff63e8b8.build_script_main.8bfffe8e-cgu.12.rcgu.o" "/home/akumar/test/abc/target/release/build/typenum-e6331931ff63e8b8/build_script_main-e6331931ff63e8b8.build_script_main.8bfffe8e-cgu.13.rcgu.o" "/home/akumar/test/abc/target/release/build/typenum-e6331931ff63e8b8/build_script_main-e6331931ff63e8b8.build_script_main.8bfffe8e-cgu.14.rcgu.o" "/home/akumar/test/abc/target/release/build/typenum-e6331931ff63e8b8/build_script_main-e6331931ff63e8b8.build_script_main.8bfffe8e-cgu.15.rcgu.o" "/home/akumar/test/abc/target/release/build/typenum-e6331931ff63e8b8/build_script_main-e6331931ff63e8b8.build_script_main.8bfffe8e-cgu.2.rcgu.o" "/home/akumar/test/abc/target/release/build/typenum-e6331931ff63e8b8/build_script_main-e6331931ff63e8b8.build_script_main.8bfffe8e-cgu.3.rcgu.o" "/home/akumar/test/abc/target/release/build/typenum-e6331931ff63e8b8/build_script_main-e6331931ff63e8b8.build_script_main.8bfffe8e-cgu.4.rcgu.o" "/home/akumar/test/abc/target/release/build/typenum-e6331931ff63e8b8/build_script_main-e6331931ff63e8b8.build_script_main.8bfffe8e-cgu.5.rcgu.o" "/home/akumar/test/abc/target/release/build/typenum-e6331931ff63e8b8/build_script_main-e6331931ff63e8b8.build_script_main.8bfffe8e-cgu.6.rcgu.o" "/home/akumar/test/abc/target/release/build/typenum-e6331931ff63e8b8/build_script_main-e6331931ff63e8b8.build_script_main.8bfffe8e-cgu.7.rcgu.o" "/home/akumar/test/abc/target/release/build/typenum-e6331931ff63e8b8/build_script_main-e6331931ff63e8b8.build_script_main.8bfffe8e-cgu.8.rcgu.o" "/home/akumar/test/abc/target/release/build/typenum-e6331931ff63e8b8/build_script_main-e6331931ff63e8b8.build_script_main.8bfffe8e-cgu.9.rcgu.o" "/home/akumar/test/abc/target/release/build/typenum-e6331931ff63e8b8/build_script_main-e6331931ff63e8b8.5at5evd65f3gjeq.rcgu.o" "-Wl,--as-needed" "-L" "/home/akumar/test/abc/target/release/deps" "-L" "/home/akumar/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/home/akumar/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-8389830094602f5a.rlib" "/home/akumar/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-41c1085b8c701d6f.rlib" "/home/akumar/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-f733fcc57ce38b99.rlib" "/home/akumar/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libmemchr-6495ec9d4ce4f37d.rlib" "/home/akumar/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-1e3796360cca5b49.rlib" "/home/akumar/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-2e7f329b154436e1.rlib" "/home/akumar/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-1e1f5b8a84008aa8.rlib" "/home/akumar/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-cbcb223c64b13cf3.rlib" "/home/akumar/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-b40bc72e060a8196.rlib" "/home/akumar/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-1eb33ae9877d3c0f.rlib" "/home/akumar/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-0335d894dd05bed7.rlib" "/home/akumar/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-076a893ead7e7ab5.rlib" "/home/akumar/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-2e924dd85b2e9d95.rlib" "/home/akumar/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-7975ffb5e62386c4.rlib" "/home/akumar/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-285425b7cea12024.rlib" "/home/akumar/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-38694d775e998991.rlib" "/home/akumar/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-914eb40be05d8663.rlib" "/home/akumar/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-27094fcca7e14863.rlib" "/home/akumar/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-919e055b306699ae.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/home/akumar/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/akumar/test/abc/target/release/build/typenum-e6331931ff63e8b8/build_script_main-e6331931ff63e8b8" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs"
  = note: collect2: fatal error: ld terminated with signal 11 [Segmentation fault], core dumped
          compilation terminated.
          

error: could not compile `typenum` (build script) due to previous error
error: failed to compile `abc-unix-relay v0.1.0 (/home/akumar/test/abc/abc-unix-relay)`, intermediate artifacts can be found at `/home/akumar/test/abc/target`

Is there a command that can help me removing the rust from scratch and install it again such that it can work, any other recommendation are also welcomed. I am using ubuntu 20.04

UPDATE

Initially I thought it's a rust problem but it's something related to "ld" and gcc compiler.

I tried a simple thing like doing and got segmentation fault

ld --version
Segmentation fault (core dumped)

my current gcc version is

 gcc --version
gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

even when I tried to compile a simple file hello.c

#include <stdio.h>
int main() {
    printf("Hello, World!\n");
    return 0;
}

I am getting the following error

collect2: fatal error: ld terminated with signal 11 [Segmentation fault], core dumped
compilation terminated.
Ankit Kumar
  • 403
  • 3
  • 8
  • 2
    `rustup self uninstall` and then reinstall `rustup`. – Eljay Jul 11 '23 at 14:54
  • No it's not working – Ankit Kumar Jul 11 '23 at 15:36
  • 1
    When it doesn't work, what doesn't it not work do? – Eljay Jul 11 '23 at 15:52
  • I tried removing rust and reinstalling it it is still giving the same error. – Ankit Kumar Jul 11 '23 at 16:02
  • 2
    Could you update your question with what you did to attempt to uninstall it. And what you did to attempt to reinstall it. Thanks! – Eljay Jul 11 '23 at 16:04
  • 2
    you could soak the machine in evaporust overnight. – Jason C Jul 11 '23 at 16:13
  • `ld` segfaulting is either a hardware problem, or a corrupted Ubuntu install. In any case this is not something that anyone on Stackoverflow would be able to diagnose, sorry. – Sam Varshavchik Jul 11 '23 at 16:43
  • @SamVarshavchik is there a way I can unistall ld and reinstall that as I think the only thing from now I can see it reinstalling Ubuntu. My hardware is fine as I have done stress-ng and it's results are stress-ng: info: [47637] Working directory /var/log is not read/writeable, some I/O tests may fail stress-ng: info: [47637] dispatching hogs: 4 cpu stress-ng: info: [47637] successful run completed in 600.08s (10 mins, 0.08 secs) – Ankit Kumar Jul 11 '23 at 16:50
  • Try reinstalling `ld`: https://askubuntu.com/questions/86923/how-can-i-reinstall-binary-file-usr-bin-ld – Eljay Jul 11 '23 at 16:58
  • I tried it I am still getting the same error ld --version Segmentation fault (core dumped) @Eljay – Ankit Kumar Jul 11 '23 at 17:14
  • If you are desperate, you could save data to another volume (like a removable drive), and reinstall Ubuntu fresh. Something seems to be awry, and without knowing what the "somehow I made some changes" is, it'll be guesswork as to figure out what got broken. – Eljay Jul 11 '23 at 17:39

2 Answers2

0
  1. Remove Rust Components:
rustup self uninstall
  1. Delete Rust Installation Directory:
rm -rf ~/.cargo
  1. Remove Cargo Cache:
rm -rf ~/.cargo/registry
  1. Remove Cargo Configurations:
rm ~/.cargo/config

But the error you're encountering seems to be related to the ld (linker) and gcc compiler on your system, rather than directly related to Rust so try to reinstall gcc and ld:

sudo apt remove --purge gcc
sudo apt install gcc
sudo apt remove --purge binutils
sudo apt install binutils
zoldxk
  • 2,632
  • 1
  • 7
  • 29
  • I am using Ubuntu20.04 – Ankit Kumar Jul 11 '23 at 16:51
  • I am getting The following packages have unmet dependencies libhdf5-mpi-dev : Depends: libhdf5-openmpi-dev but it is not going to be installed libtool : Depends: gcc but it is not going to be installed or c-compiler mpi-default-dev : Depends: libopenmpi-dev but it is not going to be installed E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages. – Ankit Kumar Jul 11 '23 at 17:17
  • Run `sudo apt --fix-broken install` to attempt resolving any broken dependencies and conflicts automatically. – zoldxk Jul 11 '23 at 17:19
  • Hi, still not working I am having the same error ? – Ankit Kumar Jul 11 '23 at 17:22
  • check this answer https://stackoverflow.com/a/57056485/15160601 – zoldxk Jul 11 '23 at 17:30
  • Did the following and getting the same error sudo apt remove --purge gcc sudo apt install gcc sudo apt remove --purge binutils sudo apt install binutils ld --version Segmentation fault (core dumped) – Ankit Kumar Jul 11 '23 at 17:30
0

I would like to summaries the solution in detail

For understanding the error , we need to understand what is ld and gcc

  1. ld (GNU linker): ld is the GNU linker, which is responsible for linking object files and libraries together to create an executable or shared library. It resolves symbols and references between different object files and libraries, ensuring that all necessary code and data are correctly linked. The linker performs tasks such as symbol resolution, relocation, symbol and section elimination, and generates the final executable or shared library file.

  2. gcc (GNU Compiler Collection): gcc is the GNU Compiler Collection, a suite of compilers for various programming languages, including C, C++, Objective-C, and others. It uses the ld linker internally for the linking phase. gcc not only compiles source code into object files but also manages the entire compilation process, including preprocessing, compiling, assembling, and linking.

Now , the problem was with ld as when I tried doing ld --version , it was giving segmentation error (A segmentation fault, often abbreviated as segfault, is a specific type of error that occurs when a program tries to access a memory location that it is not allowed to access.) so something was corrupt on my system.

You need to remove gcc and ld to resolve that issue

You can use the following commands

sudo apt remove --purge gcc
sudo apt install gcc
sudo apt remove --purge binutils
sudo apt install binutils

if above doesn't work use the following for uninstalling binutils (Both ld and gcc are part of the GNU Binutils package, which provides a collection of binary tools essential for software development, including assemblers, linkers, and object file manipulation utilities.)

sudo apt purge binutils
sudo apt remove make
sudo apt autoremove
sudo apt install build-essential

sometime you can get error like

The following packages have unmet dependencies libhdf5-mpi-dev : Depends: libhdf5-openmpi-dev but it is not going to be installed libtool : Depends: gcc but it is not going to be installed or c-compiler mpi-default-dev : Depends: libopenmpi-dev but it is not going to be installed E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.

simply remove these package and try removing binutils .

Thank You

Ankit Kumar
  • 403
  • 3
  • 8