Collect2.exe: error: LD returned 5 exit status solution

The problem
When using XP, the following errors often occur during Arduino compilation:
collect2.exe: error: ld Return5 exit status
ror failing for board Arduino Duemilanove or Diecimila
:>piling for board Arduino Duemilanove or Diecimila
: Compiling for board Arduino Duemilanove or Diecimila Do a batch of your own, rerun the faulty link section on the command line, will pop up a window, is the “memory cannot be read” error. Then he quit.

Here I’m using Arduino Ide1.6.5
After the error code tracking, the problem is not Arduino, but Windows XP NTDLL.DLL module, Arduino link program LD. Exe calls the function of NTDLL.DLL module error, when it returns (RET), into the area of no permission, only repair NTDLL.DLL can solve the above problem. This error can occur on Windows XP and Windows 7, but the forum says it won’t occur on Windows 10. There are a lot of solutions in foreign forums that use a lower version of Arduino’s LD. Exe instead. Maybe the lower version of LD. Exe doesn’t call NTDLL.DLL, but some are not very useful either.

The solution
Rename ld.exe (e.g. old-ld. exe) under C:\Programs\Arduino\hardware\tools\avr\avr\bin in IDE1.6.1, 1.6.2 or 1.6.3.
Copy LD. Exe from the lower version IDE 1.0.6 to the current version. (I’m looking for version 1.0.0, also can) to replace
reference: http://forum.arduino.cc/index.php?Topic = 316146.0.
ld exe download link:
https://download.csdn.net/download/m0_37738838/11149647
Compromise:
through observation, although links appear a mistake, but, in the target directory, has created the elf file, but have not hex file, is the link, appeared in the generated after the elf file called NTDLL. DLL errors, suspended below for the elf generated hex file work.
After analyzing the correct link process, using AVR-objcopy, using batch processing to complete the generation of ELF file to HEX file.
create an elf2hex.bat file and write the following to the elf2hext.bat file.
“D:\ Arduino-1.6.11 \hardware\tools\avr/bin/avr-objcopy” -o ihex-j. EEPROM –set-section-flags=.EEPROM =alloc,load –no-change-warnings — change-section-lma.EEPROM =0 “D:\ Arduino_Hex/ Pelican.ino.eep” “D:\ Arduino_Hex/ Pelican.ino.eep”
Replace the Pelican filename according to your application, where d:\Arduino_Hex is the target directory for the compilation of Arduino and is created by yourself [1].

(1). Collect2.exe: error: LD returned 5 exit status.
(1). Out of the race. But the ELF file has been generated.
(2). Run the elf2hex.bat file and the hex file will appear in the target.


Read More: