I’m going through the tutorial on making an OS on http://wiki.osdev.org/Bare_Bones. When I try to link boot.o and kernel.o using this command: i686-elf-gcc -T linker.ld -o myos.bin -ffreestanding -O2 -nostdlib boot.o kernel.o -lgcc , I just get this error:
collect2: fatal error: cannot find 'ld'
compilation terminated.
I just installed fresh Ubuntu 15.10 that with gcc-5.2.1 and binutils-2.25.1 .
I have searched the internet for answers but nothing helped.
asked Mar 13, 2016 at 13:28
7
I also got once the same error during a pentest while I was trying to compile my exploit on the victim server.
In my case, the directory where the «ld» program was located had not been defined in the PATH environment variable, so I simply added it.
eg. export PATH=$PATH:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin
answered Oct 29, 2019 at 7:51
I had this error while hacking a remote machine and trying to use gcc to compile an exploit on the victim machine.
I simply copied the program ld
to /tmp/
, the working directory where i was compiling my exploit exploit.c
by running
cp /usr/bin/ld /tmp/ld
followed by the original gcc compile command and the compile worked.
answered Feb 9, 2017 at 23:02
Info5ekInfo5ek
1,1974 gold badges16 silver badges25 bronze badges
2
I searched a lot to fix this issue and nothing worked but lastly i uninstalled MinGw and reinstalled it then did edited the environment variables again and then uninstalled and reinstalled vs code extensions then it worked.
answered Apr 7, 2022 at 14:41
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.
Thomas Ward♦
70.4k29 gold badges172 silver badges236 bronze badges
asked Jul 14, 2016 at 7:44
4
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!
Fabby
34.1k38 gold badges96 silver badges191 bronze badges
answered Jan 11, 2018 at 12:43
1
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
.
Zanna♦
68.2k55 gold badges210 silver badges320 bronze badges
answered Oct 25, 2016 at 9:23
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.
answered Aug 10, 2017 at 21:35
1
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
answered Mar 9, 2021 at 0:12
Type: Debugger
I am trying to run a simple Hello World
program(the issue pertains to other programs I tried too). I get the following error, when I tried to run the debugger
Executing task: /usr/bin/g++ -g /home/.../test.cpp -o /home/.../test <
collect2: fatal error: cannot find 'ld'
compilation terminated.
The terminal process terminated with exit code: 1
I tried running the command
/usr/bin/g++ -g /home/.../test.cpp -o /home/.../test
itself and it compiled successfully.
I remember using the debugger a couple of weeks ago and it used to work fine. I haven’t had any system updates since and don’t remember making an changes to any packages.
Describe the bug
- OS and Version: Manjaro Lysia 20.0.3
- VS Code Version: 1.45.1
- C/C++ Extension Version: 0.29.0
- Other extensions you installed : Only Atom One Dark Theme, which shouldn’t cause an issue
- A clear and concise description of what the bug is:
❯ which ld /bin/ld ❯ ld --version GNU ld (GNU Binutils) 2.34.0 ❯ /usr/bin/ld --version GNU ld (GNU Binutils) 2.34.0 ❯ g++ --version g++ (GCC) 10.1.0
Unable to use the debugger because of the error stated above. Issue pertains to a variety of the programs I tried it on.
To Reproduce
Steps to reproduce the behaviour:
- Write any C code
- Run the debugger
- Debugging fails with error state above
Additional context
Sample Code:
#include <iostream> using namespace std; int main() { cout<<"Hello World"; }
launch.json:
{ "version": "0.2.0", "configurations": [ { "name": "g++ - Build and debug active file", "type": "cppdbg", "request": "launch", "program": "${fileDirname}/${fileBasenameNoExtension}", "args": ["lm","W"], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "C/C++: g++ build active file", "miDebuggerPath": "/usr/bin/gdb", "logging": { "engineLogging": true, "trace": true, "traceResponse": true } } ] }
tasks.json:
{ "tasks": [ { "type": "shell", "label": "C/C++: cpp build active file", "command": "/usr/bin/cpp", "args": [ "-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}" ], "options": { "cwd": "${workspaceFolder}" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true } }, { "type": "shell", "label": "C/C++: g++ build active file", "command": "/usr/bin/g++", "args": [ "-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}" ], "options": { "cwd": "${workspaceFolder}" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true } } ], "version": "2.0.0" }
8 Years Ago
Hi guys,
Error-
collect2.exe:fatal error:cannot find 'ld'
compilation terminated
Compiler:gcc
library:mingw
I have done quite a bit of internet search and followed a discussion pertaining to this on daniweb,but to no avail.Am working on code blocks. Initially there was no problem, then i linked libws2_32.a and even though it compiled for some time with no problem, but then it started giving me the error collect2: cannot find `ld’.
I have reinstalled codeblocks, ld.bfd.exe is present in mingw, however the problem persists.
I even tried using the ld.exe from another user, but it did not work, it crashes midway.(It was just an attempt and i do understand that since ld.exe was taken from linux so it in any case did not work).
PLease help. I am new to programming on windows,ubuntu was much more comfy.
even g++ on cmd has stopped working(which is understandable). Moreover, it is creating object files, so the problem is in the linker only. Am using mingw library. No code of c++ is now working, atleast no the ones requiring the use of mingw.
Edited
8 Years Ago
by happygeek because:
moved
Когда я пытаюсь выполнить C и программу C++, я добираюсь
collect2: fatal error: cannot find 'ld' compilation terminated.
Я уже установил GCC и G ++ последняя версия.
задан
11 August 2017 в 01:44
поделиться
3 ответа
Наша команда получила ту же ошибку при создании RHEL6 DTS2 через AFL. Мы решили это использование компоновщик GNU вместо золотой компоновщик , к которому CMake, кажется, принимает значение по умолчанию.
В Ваших командных строках компилятора, наблюдении за -Wl,-fuse-ld=gold
и избавляются от него!
В нашем CMake buildsystems работавший путем вызова сценариев сборки с дополнительной опцией -DCOL_WITHOUT_GOLD
.
ответ дан Zanna
7 December 2019 в 12:39
поделиться
Можно установить золотого компоновщика через apt-get install binutils-gold
.
Для меня, который все еще дал ошибки, поскольку binutils-золото устанавливает/usr/bin/ld.gold, и через strace, кажется, что gcc хочет двоичный файл, названный с полным хостом трижды, например, x86_64-nptl-linux-gnu-ld.gold. У меня был к символьной ссылке он ln -s /usr/bin/ld.gold /usr/bin/x86_64-nptl-linux-gnu-ld.gold
, и затем все пошли прекрасные.
ответ дан Alex Miller
7 December 2019 в 12:39
поделиться
В моем случае мне разрешили это с обходным решением:
На dir мусорного ведра кросс-компилятора я сделал символьную ссылку, указывающую на компилятор
ld (ld -> powerpc-fsl-linux-ld).
Затем в make-файле или сценарии сборки я добавил папку набора инструментальных средств к переменной ПУТИ
export PATH=$PATH:"toolchain-dir-absolute-path"
это работало!
ответ дан Fabby
7 December 2019 в 12:39
поделиться
Другие вопросы по тегам:
Похожие вопросы:
I has unfortunately overridden the executable code in «/usr/bin/ld» So now ,when I run any c++ code try to execute it throws me and error
collect2: fatal error: cannot find ‘ld’
compilation terminated.
So anybody please share me the code which is in «/usr/bin/ld»
Thank you!
asked May 5, 2020 at 7:32
You should reinstall ld
using the appropriate tools for your distribution. For example, for Debian-based distributions,
sudo apt install --reinstall binutils
and for Fedora-based distributions (including RHEL and CentOS),
sudo dnf reinstall binutils
or (for older versions)
sudo yum reinstall binutils
answered May 5, 2020 at 7:48
Stephen KittStephen Kitt
388k51 gold badges996 silver badges1095 bronze badges
2
This topic has been deleted. Only users with topic management privileges can see it.
Hello everyone,
I create a console application and i didn’t add anything. But i can’t solve this problem. I downloaded many libraries but it didn’t work for me. Please help.
Thanks in advance.
@sude Did you install libc dev package?
@sude
In a terminal what does which ld
report?
@sude Are you cross compiling?
You should really provide more information about your setup.
@JonB I can not understand, there is no ld folder.
@sude said in :-1: error: collect2: fatal error: cannot find ‘ld’:
there is no ld folder.
ld is not a folder but an executable used to link your program. And you don’t have installed it — install it with your package manager.
@jsulm Actually I did not use cross compile and my program features like that.
@sude said in :-1: error: collect2: fatal error: cannot find ‘ld’:
@JonB I can not understand, there is no ld folder.
@JonB said in :-1: error: collect2: fatal error: cannot find ‘ld’:
@sude
In a terminal what doeswhich ld
report?
You just had to run that command and show its output.
Anyway if as @Christian-Ehrlicher says you don’t have the necessary package installed then that is what you need to address.
@JonB I installed but still there is an error.
@sude said in :-1: error: collect2: fatal error: cannot find ‘ld’:
I installed but still there is an error.
@JonB said in :-1: error: collect2: fatal error: cannot find ‘ld’:
@sude
In a terminal what does ‘which ld’ report?
Now the third request to execute this command…
@sude
After you have run the which ld
and reported its output.
You have not said what OS you are running on, which would help for this question. Assuming you are Ubuntu or something which works similarly, please run this command:
locate --regex '/ld$'
and show us its output.
@JonB I have rasbian but i can’t see anyting about it as you can see.
@sude said in :-1: error: collect2: fatal error: cannot find ‘ld’:
I have rasbian but i can’t see anyting about it as you can see.
Maybe a silly question, but did you install build essential package?
sudo apt install -y build-essential
@KroMignon Yes i did
@sude Just to be sure to understand what’s going wrong: do you using your RaspberryPI to build or do you build a PC?
Is Qt Creator running on RaspberryPI or on PC?
@KroMignon It is rasbian and i am using raspberry pi 3 and i use qt creator in raspberry.
@sude
Since your RPi does not have the locate
command I suggested earlier, now try:
find / -name ld -print 2>/dev/null
and show the output (better if you copy & paste the command run plus the output as text than show screen shots).
@JonB
pi@raspberrypi:~ $ which ld
pi@raspberrypi:~ $ find / -name ld -print 2>/dev/null
/usr/bin/ld
/usr/lib/compat-ld/ld
/usr/lib/gold-ld/ld
/usr/share/doc/binutils/ld
pi@raspberrypi:~ $
My terminal output is like that.
@sude
OK, hold on, that is strange.
which ld
shows no ld
executable on your PATH
.
But the find
shows /usr/bin/ld
. That should be both executable and on your PATH
.
- Output from
ls -l /usr/bin/ld
? - Output from
echo $PATH
?