undefined reference to main

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am using AVR GCC and WinAVR. Whenever I compile my program I get the following message.

c:/winavr-20080407/bin/../lib/gcc/avr/4.3.0/../../../../avr/lib/avr4/crtm8.o:(.init9+0x0): undefined reference to `main'
make: *** [final_final.elf] Error 1

I have a main function in the program defined as follows

int main (void)

I've also tried defining main as

int main()

but I still get the same error. Does anybody know what could be causing this?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Then the file that contains your main() probably is not getting built/linked for some reason.

Cliff

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is your source code compiled / part of the project in AVR Studio / Makefile? The process of creating a program needs linking (what went wrong in your case) and BEFORE a compile. If you do not compile your code but only link a program there is no main().

To give you a better support please tell how you create your AVR program and give some compiler outputs.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Blimey it took a while to spot it (I just tried #if 0'ing out bits of the code until I found the problem) but one clue was those additional } at the end of the file beyond main() - they had to be there for the file to compile which meant there were some unmatched braces somewhere and therefore main() was being defined INSIDE another function. Another clue to it was the compiler warning:

../../../../../test/var.c:289: warning: 'main' is normally a non-static function

The fault is actually:

   while (k

I bet the second brace of that inner if() is supposed to be a CLOSE brase, not an OPEN brace!

Cliff

EDIT See - this is what happens with cross-posts. I just posted this on the end of the WRONG thread - doh! :lol:

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

winavr 20080407 is bugged btw, in case you run into more problems