Arduino build error

undefined reference to `setup'

Every sketch needs a void setup() and a void loop(). The Arduino code that starts your program calls both by name.

  • Build error
  • 2 common causes
  • Seen 754 times in failed builds on Mokxi in the 30 days to November 16, 2026.
The message

What the Arduino IDE prints

Output window
core.a(main.cpp.o): In function `main':
main.cpp: undefined reference to `setup'
collect2: error: ld returned 1 exit status
exit status 1

If either is missing or misspelled, the linker finds nothing to call.

Mokxi's linker, lld, words it as undefined symbol: setup(), and the build tab explains what a sketch needs.

Causes

The 2 usual causes with the fix

1setup or loop is spelled differently

The names are lowercase. void Setup() is a different function, and the linker never finds setup.

Broken
void Setup() {
  Serial.begin(9600);
}

void loop() {
}
Fixed
void setup() {
  Serial.begin(9600);
  Serial.println("ready");
}

void loop() {
}

Mokxi’s build tab says: sketch.ino line 1 has Setup(), but Arduino calls setup()

Try this fix in Mokxi

2loop() was deleted or left out

A sketch with only setup() still needs an empty loop().

Broken
void setup() {
  Serial.begin(9600);
}
Fixed
void setup() {
  Serial.begin(9600);
  Serial.println("ready");
}

void loop() {
}

Mokxi’s build tab says: The sketch has no loop() function.

Try this fix in Mokxi

FAQ

Questions and answers

Does every sketch need both functions?

Yes. Even a sketch that does nothing in loop() needs the empty function.

Why does the message name setup and not my code?

The code that runs when the board starts calls setup() and loop(). The linker reports that call as the missing piece.

Can setup() be in another tab?

Yes, in a .ino tab, which joins the sketch. A tab that is not a .ino, .cpp or .c file is not built.