skip to Main Content

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.

2

Answers


  1. Chosen as BEST ANSWER

    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


    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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search