Arduino上“Collect2.exe: error: ld returned 5 exit status”错误的解决方法

1.运行环境

Windows xp;
Arduino1.6.11 IDE.

2.问题

在Arduino编译时,经常出现如下的错误:
collect2.exe: error: ld returned 5 exit status
exit status 1
Error compiling for board Arduino Duemilanove or Diecimila

打开Arduino中编译过程显示的开关,可以知道,编译文件时没有错误,只是在链接时出现了错误。自己做一个批处理,在命令行中重新运行出错的链接部分,会弹出一个窗口,是“内存不能为读”错误。之后就退出了。

链接问题
图1. 在命令行中重新链接时弹出的窗口

3.问题的本质

经过错误代码跟踪,问题不是出在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,但是,有的也不好用。

错误跟踪1
图2. ntdll.dll模块内出现的错误

4.折中解决方法

经过观察,虽然链接时出现了错误,但是,在目标目录中,已经生成了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】。

5.使用

(1).先正常使用Arduino编译,看是否生成elf文件(我的情况是总会生成的),有的时候,有collect2.exe: error: ld returned 5 exit status错误。退出了。但是elf文件已经生成。

(2).运行elf2hex.bat文件,在目标中会出现hex文件。

参考:
【1】Arduino设置:http://www.cnblogs.com/hyper99/p/Arduino-UNO-fang-zhen-kai-fa-huan-jing-she-zhi-he-.html

转载于:https://www.cnblogs.com/hyper99/p/Arduino-shang-Collect2exe-error-ld-returned-5-exit.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
collect2.exe: error: ld returned 5 exit status是一个与编译器相关的错误。它表示在链接阶段出现了问题。根据引用中提供的信息,这个问题可能与生成elf文件有关,但是elf文件已经生成。该问题的解决方法是运行elf2hex.bat文件,以生成hex文件。具体步骤如下: 1. 首先,确保你已经正常使用Arduino编译,并且生成了elf文件。 2. 找到elf2hex.bat文件,并运行它。这个文件应该能够将elf文件转换为hex文件。 3. 在转换的过程中,检查是否还有其他错误出现。如果没有其他错误,那么hex文件应该会在目标位置出现。 通过这些步骤,你应该能够解决QT collect2.exe: error: ld returned 5 exit status的问题。希望这能对你有帮助。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [QT中遇到的编译错误与警告及其解决方法汇总](https://blog.csdn.net/qq_43792862/article/details/97391319)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [collect2.exe: error: ld returned 5 exit status解决方案](https://blog.csdn.net/m0_37738838/article/details/89636787)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [qt环境安装](https://download.csdn.net/download/hanqian3956/5943951)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值