xiangzh1983 发表于 2011-3-25 09:46:06

求助ICC编译问题

我在编译成功一个工程后,想用main.o文件代替mian.c进行编译时,总是提示!ERROR file 'crtatmega.o': undefined symbol '_main'错误。
    我想问下怎么解决上述问题,以及怎么用.o文件来代替.c文件进行编译,我用的编译器是ICC7.31


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

machao 发表于 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.

xiangzh1983 发表于 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文件?

      期待您的回复,谢谢

xiangzh1983 发表于 2011-4-8 12:31:07

回复【2楼】xiangzh1983
-----------------------------------------------------------------------

    马老师,我已经明白了ICC怎么编译生成最终的.hex文件,但是我通过看.map文件看到ICC编译时生成了很多内部函数。
    我想请问下,有没有方法编译方法或者编译器不生成内部函数的?
页: [1]
查看完整版本: 求助ICC编译问题