I have the following headers and source files:
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
#include "AVR_comunic.h"
void USART_Flush( void )
{
...
}
void USART_Init( unsigned int ubrr)
{
...
}
int USART_WriteChar(unsigned char data)
{
...
}
and 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
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?
avr-objdumpneeds to be afteravr-gcc ... -o AVR_comunic.elfas that's what createsAVR_comunic.elf. Second why aren't you usingmain_f.elfas that's wheremainshould be part of the the object. I don't see howAVR_comunic.elfcontainsmaineither, given it's only object fileAVR_comunic.o.make