0

It's my second post here, i have a huge problem which prevents me to study so i have to fix it as soon as it's possible !

My gcc was working fine and i had to work on FairThreads (in C). I downloaded the following archive :

Fair Threads

As you can see, in /src there's a makeFile, i replaced the second line which was :

LIB_DIR     = ../lib

by LIB_DIR = /usr/bin/ld

and i compiled the makeFile by the command "make"

And now, i cannot compile any c/c++ program anymore. Even a hello world program.

I got the following error message on the terminal for every compiling attempt :

/usr/bin/ld: 2: /usr/bin/ld: Syntax error: newline unexpected
collect2: error: ld returned 2 exit status

I have found on the net this solution but it doesn't work for me :

sudo apt-get autoremove binutils    
sudo apt-get install binutils

I also tried to reinstall gcc, when executing :

sudo apt-get purge gcc 

i got :

Des erreurs ont été rencontrées pendant l'exécution :
  linux-firmware
  linux-image-generic-hwe-18.04
  linux-generic-hwe-18.04
E: Sub-process /usr/bin/dpkg returned an error code (1)

but when i trie a gcc --version it tells me that it is not found.

So when i execute the command to reintall it :

sudo apt-get install gcc 

i also get :

Des erreurs ont été rencontrées pendant l'exécution :
 linux-firmware
 linux-image-generic-hwe-18.04
 linux-generic-hwe-18.04
 linux-image-5.4.0-72-generic
 initramfs-tools
E: Sub-process /usr/bin/dpkg returned an error code (1)

but gcc --version tellls that it's installed.

Finally, when i trie to compile a program, i got :

/usr/bin/ld: 2: /usr/bin/ld: Syntax error: newline unexpected
collect2: error: ld returned 2 exit status

I hope that i explained well, and i'll get a solution for this :/, as a computer science student, i can't do anything without gcc :(

EDIT 1 :

When i try to remove bin/ld by executing :

sudo rm -fr /usr/bin/ld;sudo apt-get install --reinstall binutils

i got :

Des erreurs ont été rencontrées pendant l'exécution :
 linux-firmware
 linux-image-generic-hwe-18.04
 linux-generic-hwe-18.04
 linux-image-5.4.0-72-generic
 initramfs-tools
E: Sub-process /usr/bin/dpkg returned an error code (1)

and this particular error message :

WARNING: no ldd around - install libc-bin

EDIT :

I have installed ldd by the command :

sudo apt-get install libc-bin

still no changes...

5
  • 5
    why did you change LIB_DIR (which should point to a directory containing linkable libraries) to the /usr/bin/ld binary?
    – cas
    Apr 19, 2021 at 14:36
  • 1
    Is /usr/bin/ld a directory now? if so, delete it (and everything it contains) with rm -rf /usr/bin/ld/, and reinstall ld. apt-get reinstall binutils.
    – cas
    Apr 19, 2021 at 14:38
  • Well, you seem to also be missing ldd. Try to follow the suggestion sudo apt-get install libc-bin.It seems you did more than what is in the original question. It's not easy to help you recover from things we don't know about. Hope reinstalling libc-bin works. Apr 19, 2021 at 15:24
  • i installed it but no changes... Apr 19, 2021 at 15:26
  • @cas it was a mistake, i miss-followed the readme.. Apr 19, 2021 at 15:33

1 Answer 1

3

You overwrote the binary /usr/bin/ld (although you do not say so, I assume you ran make as root).

You will have to remove and reinstall /usr/bin/ld to have a sane build environment.

If you are on a Debian derivative, sudo rm -rf /usr/bin/ld;sudo apt-get install --reinstall binutils should do it.

5
  • dpkg can behave oddly (i.e. fail to install/reinstall/remove/etc packages but with the extra "fun" of not-very-helpful or even misleading error messages) when it finds non-files (like directories) where it expects to be able to create a file. The bogus non-file needs to be removed before the package(s) can be installed.
    – cas
    Apr 19, 2021 at 14:45
  • @cas the thing is that in this case ld was overwritten with another file, not a directory (I checked by running it on the actual source and pointing LIB_DIR to a file). But in general terms yes, I agree, removing the offending file/directory is a better idea. Should I update the answer? Apr 19, 2021 at 14:50
  • 1
    if it was replaced with a file, your answer is a good enough for this particular question. +1 from me. It wouldn't hurt to add a note about what to do if a directory or pipe or whatever is obstructing a package. In general, if you know what file or file-like-thing is obstructing the reinstall, then delete it before re-installing.
    – cas
    Apr 19, 2021 at 14:55
  • Done, thanks @cas. Apr 19, 2021 at 15:01
  • @EduardoTrápani i had issues when executing the command, i paste an edit on your comment Apr 19, 2021 at 15:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .