undefined reference to 'loop' (or 'setup')

  • Arduino C++

You may see

undefined reference to `loop'
undefined reference to `setup'
collect2.exe: error: ld returned 1 exit status

Why it happens

  • void setup() or void loop() is missing or misspelt.
  • Only part of the code was copied.

How to fix it

  1. Copy the whole code block from the lesson with its Copy button.
  2. Check there's exactly one void setup() and one void loop(), in small letters.

It worked if: Verify passes.

Seen in a real run (some lines are close variants of it). Produced with Arduino CLI 1.5.1 and Arduino AVR core 1.8.8 (the same compiler the Arduino IDE uses).

Didn't help? Search another error or ask us.