搜索
bottom↓
回复: 3

求助ICC编译问题

[复制链接]

出0入0汤圆

发表于 2011-3-25 09:46:06 | 显示全部楼层 |阅读模式
我在编译成功一个工程后,想用main.o文件代替mian.c进行编译时,总是提示!ERROR file 'crtatmega.o': undefined symbol '_main'错误。
    我想问下怎么解决上述问题,以及怎么用.o文件来代替.c文件进行编译,我用的编译器是ICC7.31


      请知道的帮忙回答下,万分感谢!!

阿莫论坛20周年了!感谢大家的支持与爱护!!

一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。

出0入0汤圆

发表于 2011-4-2 12:21:48 | 显示全部楼层
不知道是否可以,尝试一下


The linker links in the startup file before your files, and links the standard library libcavr.a with your program. The startup file is one of the following depending on the target device:

crtavr.o                Normal startup file
        crtatmega.o                ATmega startup. Uses "jmp __start" as the reset vector
        crtavrram.o                Normal startup file that also initializes the external SRAM
        crtatmegaram.o        ATmega startup file that also initializes the external SRAM
        crtboot.o                Normal bootloader startup file. Differs from crtavr.o in that it relocates the interrupt vector.
        crtboothi.o                Same as crtboot.o but uses ELPM and initializes RAMPZ to 1.

You may create your own startup file if you wish. See Project->Options->Target->NonDefaultStartup The startup file defines a global symbol __start which is the starting point of your program. The startup file functions are:

1.        Initialize the hardware and software stack pointers.
2.        Copy the initialized data from the idata area to the data area.
3.        Initialize the bss area to zero.
4.        Call the user main routine.
5.        Define the entry point for exit, which is defined as an infinite loop. If main ever returns, it will enter exit and gets stuck there (so much for "exit").

The startup also defines the reset vector. You do not need to modify the startup file to use other interrupts, see Interrupt Handlers. Compiling or assembling the startup file requires a special switch to the assembler (-n). You can still use the IDE to compile a Startup file, just use the File->CompilerFileTo...StartupFileToObject command.

To modify and use a new startup file:

cd \icc\libsrc.avr                ; or wherever you install the compiler

<edit crtavr.s>

<open crtavr.s using the IDE>        ;

<Choose "Compile File To->Object">        ;generate a new crtavr.o

copy crtavr.o ..\lib                ; copy to the library directory

Note that you must either specify the startup with an absolute pathname or it must be located in the directory specified by the Project Options Library path.

出0入0汤圆

 楼主| 发表于 2011-4-6 17:35:18 | 显示全部楼层
回复【1楼】machao
-----------------------------------------------------------------------

     马老师,谢谢您的回复!
     我把一个程序编译后,用mian.o生成库文件.a就可以实现编译了。
     我看了一下:.a文件与.o文件的区别就是.a文件在开头有.start和结尾有.end
     中间的内容完全一样,感觉.o为什么会提示找不到_main应该还是编译器编译的问题。

     另外,马老师,我用的编译器是ICC的,我想请教下您
     ICC的编译详细流程,我在ICC帮助里只看到了如下文件:

1.The compiler compiles each C source file to an assembly file.
2.The assembler translates each assembly file (either from the compiler or assembly files that you have written) into a relocatable object file.
3.After all the files have been translated into object files, the linker combines them together to form an executable file. In addition, a map file, a listing file, and debug information files are also output.
     
我想知道具体的过程,比如说第一步编译器是通过那个工具使C代码转为汇编代码,然后按什么流程生成最终的.hex文件?

      期待您的回复,谢谢

出0入0汤圆

 楼主| 发表于 2011-4-8 12:31:07 | 显示全部楼层
回复【2楼】xiangzh1983
-----------------------------------------------------------------------

    马老师,我已经明白了ICC怎么编译生成最终的.hex文件,但是我通过看.map文件看到ICC编译时生成了很多内部函数。
    我想请问下,有没有方法编译方法或者编译器不生成内部函数的?
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-3-29 02:56

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

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