Unsolved problem for many years: undefined reference to `main’ ERROR

It is a error that any sketch can not be compiled with (No programming error. Initial blank sketch can not be also compiled)

'__vector_xx ~~~~~~~~~~~~~~~
undefined reference to `main', collect2.exe: error: ld returned 1 exit status
exit status 1

I have searched the solutions but I found only simillar posts that remain unresolved.

Is there any one who solved this problem?

A partial solution I found is downgrading the version of 'Arduino AVR Boards' in Board Manager.

In 1.6.5 Version of Arduino AVR Boards, a sketch can be compiled with Boards: Arduino nano,

Arduino leonardo and so on(I didn't check other boards but there will be no problems)

I want to use 'Arduino Uno WiFi rev2, but it belongs to 'megaAVR Boards'.

Unfortunately, in any version of 'megaAVR Boards', I can not compile a sketch.

I already tried removing and re-installing.

I have download magaAVR core and my sketch compiles.
deinstall IDE. remove any folder referenced to it at 4 places and in windows register

  1. C:\Users\<username>\AppData\Local\Temp\arduino_build_...
  2. C:\Users\<username>\AppData\Local\Arduino15
  3. C:\Program Files (x86)\Arduino
  4. sketch folder

Thank you for reply. I already removed the folders and registry and re-installed, but it didn't work.

try on another PC. if not lucky throw faulty boards in a bin.

This has nothing to do with faulty boards.

It looks like the library containing the definition of "main" (Arduino core) is linked before the library that references "main" (crtlib?). Since the 'main' is not yet referenced, that object file is not linked in.

I wonder if putting this line in your sketch would help:

extern int main(void);
1 Like

Thanks for your comment. I tried but it doesn't work.

I have never had that problem.

What is your environment? (OS, OS version, how the IDE was installed, etc.)

Probably you need to completely clean out the current bad installation before re-installing, and that's more difficult than it could be, since in some OSes various pieces are scattered all over the place.

Hi, I don't know why this problem occurs. If you search google with undefined reference to `main’ keywords, you will find similar posts.

My OS is windows10, arduino version IDE is 1.8.19

I tried cleaning the arduino completely. I removed Arduino IDE, C:\Users(USER_ID)\AppData\Local\Arduino15, C:\Users(USER_ID)\AppData\Local\Temp(arduino temp folders...) and

related registries but with no effect.

2022년 4월 30일 (토) 오후 5:06, WestfW via Arduino Forum <arduino@discoursemail.com>님이 작성:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.