极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 14905|回复: 2

编译错误: crtm2560.o:(.init9+0x0): undefined reference to `main' collect2.exe...

[复制链接]
发表于 2015-6-12 00:23:23 | 显示全部楼层 |阅读模式
##在arduino在1.6.4版本编译出错:




Arduino:1.6.4 (Windows 7), 板:"Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

c:/program files/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.8.1/../../../../avr/lib/avr6/crtm2560.o.init9+0x0): undefined reference to `main'
collect2.exe: error: ld returned 1 exit status


##高版本不支持文件名为 mian.ino 的工程名,di
##估计是编译时导致与系统生成的文件冲突,
##解决方案在高版本上不要命名为main.ino
##虽然定义int main() 函数可以编译通过但是程序入口改为main函数,烧录运行时串口输出不正常

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

发表于 2015-6-12 02:00:14 | 显示全部楼层
main 本身是 c/c++ 中 reserve 了特別用途.
而 arduino IDE 中亦定義了 main, 而 setup() 及 loop() 都是由 main 觸發的:



  1. #include <Arduino.h>

  2. //Declared weak in Arduino.h to allow user redefinitions.
  3. int atexit(void (*func)()) { return 0; }

  4. // Weak empty variant initialization function.
  5. // May be redefined by variant files.
  6. void initVariant() __attribute__((weak));
  7. void initVariant() { }

  8. int main(void)
  9. {
  10.         init();

  11.         initVariant();

  12. #if defined(USBCON)
  13.         USBDevice.attach();
  14. #endif
  15.        
  16.         setup();
  17.    
  18.         for (;;) {
  19.                 loop();
  20.                 if (serialEventRun) serialEventRun();
  21.         }
  22.         
  23.         return 0;
  24. }
复制代码
回复 支持 反对

使用道具 举报

发表于 2015-6-12 15:14:15 | 显示全部楼层
Super169 发表于 2015-6-12 02:00
main 本身是 c/c++ 中 reserve 了特別用途.
而 arduino IDE 中亦定義了 main, 而 setup() 及 loop() 都是由 ...

                学习了
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-16 21:14 , Processed in 0.036674 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表