[英]Linking multiple object files into a binary AVR GCC
I have the following headers and source files: 我有以下头文件和源文件:
AVR_comunic.h AVR_comunic.h
#ifndef AVR_COMUNIC_H_
#define AVR_COMUNIC_H_
#include<avr/io.h>
#define FOSC 20000000UL // Clock Speed
#define BAUD 19200
#define MYUBRR FOSC/16/BAUD-1
void USART_Init( unsigned int);
int USART_WriteChar(unsigned char);
// int USART_Receive( unsigned char *);
void USART_Flush(void);
#endif /* AVR_COMUNIC_H_ */
AVR_comunic.c AVR_comunic.c
#include "AVR_comunic.h"
void USART_Flush( void )
{
...
}
void USART_Init( unsigned int ubrr)
{
...
}
int USART_WriteChar(unsigned char data)
{
...
}
and main_f.c 和main_f.c
#include"AVR_comunic.h"
void init_ports()
{
DDRD|= (1<<PD7);
}
int main(void)
{
init_ports();
...
while(1)
{
// now what?
}
return 1;
}
I wrote a batch file in Notepad++ to obtain the .hex file for this program 我在Notepad ++中编写了一个批处理文件以获得该程序的.hex文件
COMPILE_BUILD.bat COMPILE_BUILD.bat
ECHO OFF
ECHO ----------------------------------------------------------
ECHO ----- executing your commands : compile and build -------
ECHO ----------------------------------------------------------
avr-gcc -g -Wall -Os -DF_CPU=20000000UL -mmcu=atmega88p -c AVR_comunic.c
avr-gcc -g -Wall -Os -DF_CPU=20000000UL -mmcu=atmega88p -c main_f.c
avr-gcc -g -mmcu=atmega88p -o AVR_comunic.elf main_f.o AVR_comunic.o
avr-objdump -h -S AVR_comunic.elf > AVR_comunic.lst
avr-gcc -g -mmcu=atmega8 -Wl,-Map,AVR_comunic.map -o AVR_comunic.elf AVR_comunic.o
avr-objcopy -j .text -j .data -O ihex AVR_comunic.elf AVR_comunic.hex
ECHO ----------------------------------------------------------
ECHO ---------------------- happy ? ---------------------------
ECHO ----------------------------------------------------------
pause
I get the following error: 我收到以下错误:
... : undefined reference to 'main'
avr-objcopy: 'AVR_comunic.elf' no such file
I understand from the information on internet that the linker does thinks that there is no "main" function ... but it is ... what am I doing wrong? 我从互联网上的信息中了解到,链接器确实认为没有“主要”功能……但这是……我做错了什么? Or how should I write to compile multiple source files?
还是应该编写以编译多个源文件?
I understand from the information on internet that the linker does thinks that there is no "main" function ... but it is ... what am I doing wrong?
我从互联网上的信息中了解到,链接器确实认为没有“主要”功能……但这是……我做错了什么?
This command: 该命令:
avr-objdump -h -S AVR_comunic.elf > AVR_comunic.lst
attempts to extract info from AVR_communic.elf
, which isn't produced yet. 尝试从尚未生成的
AVR_communic.elf
提取信息。 You want to move it after this command: 您要在以下命令后移动它:
avr-gcc -g -mmcu=atmega8 -Wl,-Map,AVR_comunic.map -o AVR_comunic.elf AVR_comunic.o
The above command fails with undefined reference to: 'main'
because you are not linking main_f.o
into it. 上面的命令以
undefined reference to: 'main'
失败undefined reference to: 'main'
因为您没有将main_f.o
链接到其中。
It appears that what you really want is: 看来您真正想要的是:
avr-gcc -g -mmcu=atmega88p -o AVR_communic.elf main_f.o AVR_comunic.o
avr-objdump -h -S AVR_comunic.elf > AVR_comunic.lst
avr-objcopy -j .text -j .data -O ihex AVR_comunic.elf AVR_comunic.hex
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.