3

When I try to run C and C++program I am getting

collect2: fatal error: cannot find 'ld' compilation terminated.

I have already installed GCC and G++ latest version.

4
  • you need libc6-dev. Do sudo apt-get install libc6-dev and if gets installed (if it's not already installed), try compiling your C/C++ programs again
    – Zanna
    Commented Jul 14, 2016 at 7:56
  • libc6-dev is already the newest version (2.23-0ubuntu3). But no joy yet Commented Jul 14, 2016 at 8:08
  • What do gcc -print-prog-name=ld, which ld and dpkg -V binutils say? Commented Jul 14, 2016 at 12:19
  • gcc -print-prog-name=ld show ld , which ld= /usr/bin/ld , dpkg -V binutils = blank This is nginx issue because when I switch to apache it seems fine Commented Jul 14, 2016 at 15:12

4 Answers 4

3

In my case I had this resolved with a workaround:

On the cross-compiler bin dir I made a symlink pointing to the compiler

ld (ld -> powerpc-fsl-linux-ld). 

Then in the makefile or build script I added the toolchain folder to the PATH variable

export PATH=$PATH:"toolchain-dir-absolute-path"

it worked!

1
2

Our team got the same error when building RHEL6 DTS2 via AFL. We solved this using GNU linker instead of gold linker to which CMake seems to default.

In your compiler command lines, lookout for -Wl,-fuse-ld=gold and get rid of it!

In our CMake buildsystems this worked by invoking the build scripts with additional option -DCOL_WITHOUT_GOLD.

2

You can install the gold linker via apt-get install binutils-gold.

For me, that still gave errors, as binutils-gold installs a /usr/bin/ld.gold, and via strace, it appears gcc wants a binary named with the full host triple, e.g. x86_64-nptl-linux-gnu-ld.gold. I had to symlink it ln -s /usr/bin/ld.gold /usr/bin/x86_64-nptl-linux-gnu-ld.gold, and then all went fine.

1
  • Thanks for the tip!! For lld I had to do the following: ln -s /usr/bin/lld-8 /usr/bin/ld.lld Commented Mar 13, 2020 at 0:43
0

For whatever reason, my /usr/bin/ld.bfd permissions did not allow read or execute for all users. chmod a+rx /usr/bin/ld.bfd fixed my problem

You must log in to answer this question.

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