Search code examples
gcccompilationundefined-referenceavr-gccatmega32

crtatmega328p.o:(.init9+0x0): undefined reference to "main"


I have been trying to compile a robot simulation.

I created an empty file called test.c and tried to compile a test using:

avr-gcc -mmcu=atmega328p test.c

AVR-GCC it's installed

copt@copt:~$ avr-gcc --version
avr-gcc (GCC) 5.4.0
Copyright (C) 2015 Free Software Foundation, Inc.
Este é um software livre; veja as fontes para as condições de cópia. NÃO HÁ
garantias; nem mesmo de COMERCIALIZAÇÃO ou ADEQUAÇÃO A UMA FINALIDADE
ESPECÍFICA.

and returned this:

/usr/lib/gcc/avr/5.4.0/../../../avr/lib/avr5/crtatmega328p.o:      
(.init9+0x0): reference not defined to "main"
collect2: erro: ld returned 1 exit status

Very similar to the principal one that I've been trying to make work. I think if solve this very basic problem, the biggest one will be solved.

FLAGS = -mmcu=atmega328p -Wall -gdwarf-2 -O3 -funsigned-char -funsigned-   bitfields -fpack-struct -fshort-enums 

It should be compiling normally.


Solution

  • For me it turned out that I had saved the code as the default FILE type. I found after I saved it as a .c file it was able to compile.