天天看點

collect2.exe: error: ld returned 5 exit status解決方案

問題

使用xp系統,在Arduino編譯時,經常出現如下的錯誤:

collect2.exe: error: ld returned 5 exit status

exit status 1

Error compiling for board Arduino Duemilanove or Diecimila

打開Arduino中編譯過程顯示的開關,可以知道,編譯檔案時沒有錯誤,隻是在連結時出現了錯誤。自己做一個批處理,在指令行中重新運作出錯的連結部分,會彈出一個視窗,是“記憶體不能為讀”錯誤。之後就退出了。

collect2.exe: error: ld returned 5 exit status解決方案

在這裡我使用是arduino IDE1.6.5

經過錯誤代碼跟蹤,問題不是出在Arduino上,而是在windows XP的ntdll.dll子產品上,Arduino的連結程式ld.exe調用了ntdll.dll子產品的功能時出了錯誤,在其中傳回(ret)時,進入了無權限的區域,隻有修複ntdll.dll才可以從根本上解決以上問題。在windows xp和windows 7上可能會出現上邊的錯誤,而論壇中說,在windows 10上不會出現上邊的問題。在國外的論壇上有大量的用低版本的Arduino的ld.exe代替的解決方法,可能是低版本的ld.exe不調用ntdll.dll,但是,有的也不好用。

collect2.exe: error: ld returned 5 exit status解決方案

解決辦法

在ide1.6.1, 1.6.2 or 1.6.3,(我的是1.6.5)的安裝路徑C:\Programs\Arduino\hardware\tools\avr\avr\bin下 重命名ld.exe (例如OLD-ld.exe);

複制低版本ide 1.0.6的ld.exe到目前版本。(我找的是1.0.0版的,也可以)進行替換

參考:http://forum.arduino.cc/index.php?topic=316146.0

ld.exe下載下傳連結:

https://download.csdn.net/download/m0_37738838/11149647

折中辦法:

經過觀察,雖然連結時出現了錯誤,但是,在目标目錄中,已經生成了elf檔案,卻沒有hex檔案,也就是連結時,在生成elf檔案後出現了調用ntdll.dll的錯誤, 中止了下邊要進行的elf生成hex檔案的工作。

經過分析正确的連結過程,使用avr-objcopy,用批處理完成elf檔案到hex檔案的生成。

建立一個elf2hex.bat檔案,把如下内容寫到elf2hext.bat檔案中。

“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.elf” “d:\Arduino_Hex/pelican.ino.eep”

“D:\arduino-1.6.11\hardware\tools\avr/bin/avr-objcopy” -O ihex -R .eeprom “d:\Arduino_Hex/pelican.ino.elf” “d:\Arduino_Hex/pelican.ino.hex”

根據你的應用,替換掉pelican檔案名,其中d:\Arduino_Hex是Arduino編譯的目标目錄,是自己建立的【1】。

使用

(1).先正常使用Arduino編譯,看是否生成elf檔案(我的情況是總會生成的),有的時候,有collect2.exe: error: ld returned 5 exit status錯誤。退出了。但是elf檔案已經生成。

(2).運作elf2hex.bat檔案,在目标中會出現hex檔案。

繼續閱讀