gcclinkerlinker-errorsgnu-toolchainlinker-flags

collect2: fatal error: cannot find ‘ld’ compilation terminated. , binutils installed


I had been working on generation of shared libraries, while installing linpack i accidentally replaced cp linpack-fpm/lib/liblinpack.a /usr/bin/ld , I had tried referring to various solutions like sudo apt-get install --reinstall binutils but it has not been working for me. while trying to compile a simple c file
henil@henil:~/Downloads/fortran-sphinx/fpm-dependencies$ gcc hello.c collect2: fatal error: cannot find ‘ld’ compilation terminated.
I have also tried to check for symlinks, but could not find a suitable fix. I would be happy to provide any further information for debugging.
Thanks.


Solution

  • I was finally able to debug this, while trying to fix this issue i had in turn broken a lot of symlinks and also tried various approaches which had complicated the issue much more , then the only way to fix it that worked was to reinstall all the packages using
    sudo apt-get install --reinstall $(dpkg -l | grep ^ii | awk '{print $2}')

    this command reinstalls all currently installed packages on the system, effectively refreshing their installations. This can be useful for fixing issues related to corrupted or misconfigured packages.