redefinition of 'void setup()'

  • Arduino C++
  • ESP32

You may see

error: redefinition of 'void setup()'
error: redefinition of 'int a'
note: 'void setup()' previously defined here

Why it happens

  • Two programs were pasted into one sketch.
  • There are two .ino tabs in the same folder. The IDE joins them together.
  • A variable is created twice.

How to fix it

  1. Keep only one void setup() and one void loop().
  2. Joining two lessons? Move the lines from both setups into one setup, and the same for loop.
  3. Look at the tabs at the top of the IDE and remove the ones you don't need.

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.