undefined reference to 'setup'
The Arduino compiler's linker failed to find the mandatory setup() function. Every standard Arduino sketch requires both a setup() and a loop() function to successfully link into an executable.
During the Arduino build process, a hidden core file named main.cpp acts as the primary entry point (the main function) for the generated C++ application. This core file initializes the microcontroller and then explicitly calls a user-provided setup() function exactly once. Following this, it enters an infinite loop that calls the loop() function. When compilation finishes compiling individual source files and reaches the final linking stage, the linker attempts to resolve the references in main.cpp to the actual function definitions provided in your sketch. If the linker cannot locate a definition for setup(), it emits an 'undefined reference' error because the final executable is incomplete and cannot be built.
This diagnostic is triggered when the setup() function is absent from the compiled sketch. The most common cause is simply forgetting to include the void setup() block, or attempting to compile a completely empty file. Because C++ is strictly case-sensitive, the error will also occur if the function is incorrectly capitalized (e.g., void Setup() or void set_up()), as the linker is looking for the exact symbol 'setup'. Additionally, placing the setup() function inside another function, accidentally commenting it out, or wrapping it in a disabled preprocessor macro (such as #if 0) will prevent it from being compiled and passed to the linker.
void loop() {
// The loop is present, but setup is completely missing
}
Define the setup() function in your sketch, ensuring correct spelling, capitalization, and placement.
```C++
void setup() {
// Initialization code runs once
}
void loop() {
// Main code runs repeatedly
}
```