My Makefile to AVR project doesn’t compile the program

  avr, avr-gcc, c++, lcd, makefile

I have been learning the make program. I wanna to program LCD by the AtMega8 and compile it with the Makefile. I wrote this basic code:

#ifndef __AVR_ATmega8__
#define __AVR_ATmega8__
#endif
 
#define F_CPU 8000000UL
 
#include <avr/io.h>
#include <util/delay.h>
#include "hd44780.h"
 
 
int main(void)
{   
    lcd_init();
    lcd_clrscr();
    lcd_puts("Hello World");
 
    while (1);
 
    return 0;
}

And I wrote this Makefile:

all: main.hex clean
 
main.o: main.cpp hd44780.h
    avr-gcc -Wall -Os -mmcu=atmega8 -c $< -o [email protected]
 
main.elf: main.o
    avr-gcc -Wall -Os -mmcu=atmega8 -o main.elf main.o
 
main.hex: main.elf
    avr-objcopy -j .text -j .data -O ihex main.elf main.hex
    avr-size --format=avr --mcu=atmega8 main.elf
 
.PHONY: clean
clean:
    rm main.o main.elf

During compilation the make shows error:

avr-gcc -Wall -Os -mmcu=atmega8 -o main.elf main.o
main.o: In function `main':
main.cpp:(.text+0x94): undefined reference to `lcd_init()'
main.cpp:(.text+0x96): undefined reference to `lcd_clrscr()'
main.cpp:(.text+0x9c): undefined reference to `lcd_puts(char const*)'
make: *** [main.elf] Error 1

What is the problem?

Source: Windows Questions C++

LEAVE A COMMENT