Arduino compilation errors usually fall into a few predictable buckets:
- Syntax errors: missing semicolons, braces, quotes
- Name/Scope errors: variables/functions not declared, wrong casing
- Type errors: mixing incompatible types, wrong function signatures
- Library errors: missing libraries, wrong versions, wrong include names
- Board/port setup errors: wrong board selected, missing core packages
- C/C++ gotchas: prototypes, header guards, multiple definitions
This guide talks about the most common compile-time messages, what they mean, and how to fix them. There are a lot of short code examples in it that you can copy and paste into the IDE to see the problem and figure it out.
Quick Checklist
Before digging into the specific error message:
- Read the first error in the output panel (later errors are often “noise”).
- Confirm Tools → Board matches your actual board.
- Confirm Tools → Processor (if applicable) matches (common with Nano).
- If the error mentions a header like
SomeLib.h, verify the library is installed. - If it mentions
avr-g++/xtensa-esp32-elf-g++/ similar, it’s a compile step issue (not upload). - If it mentions
ldor “linking”, it’s usually duplicate definitions or missing implementations.
1) expected ';' before ...
What it means
You missed a semicolon at the end of a statement, or you ended a line in a way the compiler can’t interpret.
Example that fails
void setup() {
int x = 10
Serial.begin(9600);
}
void loop() {}
Fix
void setup() {
int x = 10;
Serial.begin(9600);
}
void loop() {}
Common hidden cause: missing semicolon after a struct
struct Config {
int threshold;
} // missing semicolon here
void setup() {}
void loop() {}
Fix:
struct Config {
int threshold;
};
2) expected '}' at end of input
What it means
You opened a { block but didn’t close it.
Example that fails
void setup() {
if (true) {
// do something
}
void loop() {}
Fix
void setup() {
if (true) {
// do something
}
}
void loop() {}
Tip
In Arduino IDE, click near a brace and it highlights the matching pair. If it doesn’t, you’ve likely got an imbalance.
3) 'xyz' was not declared in this scope
What it means
You used a variable or function name the compiler can’t see where you used it. Usually:
- Misspelling / wrong capitalization
- Declared inside a different block (scope issue)
- Missing function prototype (more common in .cpp files than .ino)
Example that fails: scope problem
void setup() {
int ledPin = 13;
}
void loop() {
digitalWrite(ledPin, HIGH); // ledPin not visible here
}
Fix: make it global
int ledPin = 13;
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
digitalWrite(ledPin, HIGH);
}
Example that fails: capitalization
int LedPin = 13;
void setup() {
pinMode(ledpin, OUTPUT); // wrong casing
}
void loop() {}
Fix:
pinMode(LedPin, OUTPUT);
4) redefinition of '...'
What it means
You defined the same variable/function twice in the same translation unit.
Example that fails
int value = 10;
int value = 20; // redefinition
void setup() {}
void loop() {}
Fix
Rename one variable or remove the duplicate:
int value = 10;
int value2 = 20;
5) multiple definition of '...' (Linker error)
What it means
You defined the same global symbol in more than one file (common when using .h files incorrectly).
Classic cause: defining globals in a header
Bad: MyVars.h
int counter = 0; // definition in header (bad)
Included in multiple .cpp/.ino files → multiple definitions.
Fix approach
MyVars.h
extern int counter; // declaration only
MyVars.cpp
int counter = 0; // single definition
6) undefined reference to '...' (Linker error)
What it means
You declared a function but never provided its implementation, or you forgot to compile/link the file that contains it.
Example that fails
void doThing(); // declared but not defined
void setup() {
doThing();
}
void loop() {}
Fix
void doThing() {
// implementation
}
void setup() {
doThing();
}
void loop() {}
Another common cause
You created a .cpp file but didn’t place it inside the sketch folder (or library folder) correctly, so it never builds.
7) no matching function for call to ...
What it means
You called a function with the wrong number or types of arguments.
Example that fails
void setup() {
pinMode(13); // missing second argument
}
void loop() {}
Fix
void setup() {
pinMode(13, OUTPUT);
}
void loop() {}
Another example: wrong type
void setup() {
digitalWrite(13, 2); // should be HIGH/LOW
}
void loop() {}
Fix:
digitalWrite(13, HIGH);
8) invalid conversion from '...' to '...'
What it means
You’re forcing a type conversion the compiler won’t allow safely.
Example that fails: string literal to char*
void setup() {
char* name = "Arduino"; // string literal is const char[]
}
void loop() {}
Fix
void setup() {
const char* name = "Arduino";
}
void loop() {}
Example that fails: float to int pointer (typical library misuse)
int* p = 3.14; // nonsense conversion
Fix: use correct type or correct variable:
float x = 3.14;
9) conflicting declaration / conflicting types for ...
What it means
You declared the same function/variable with different types.
Example that fails
int readSensor();
float readSensor() { return 1.2; } // conflict
Fix
Make the declaration match the definition:
float readSensor() { return 1.2; }
10) expected primary-expression before ...
What it means
Often caused by:
- Missing parentheses
- Extra commas
- Using
=instead of== - Broken function call syntax
Example that fails
void setup() {
int x = (5 + ); // incomplete expression
}
void loop() {}
Fix:
int x = (5 + 3);
Another common one: stray comma
digitalWrite(13, HIGH,);
Fix:
digitalWrite(13, HIGH);
11) stray '\xxx' in program
What it means
You pasted a weird character into the code: smart quotes, non-breaking spaces, or other invisible Unicode.
Example that fails
Serial.println(“Hello”); // smart quotes
Fix
Use normal quotes:
Serial.println("Hello");
Tip: retype quotes manually if you copied from a webpage.
12) #include <SomeLib.h>: No such file or directory
What it means
The compiler can’t find the library header. Causes:
- Library not installed
- Wrong header name
- Library incompatible with selected board/core
Example that fails
#include <NonexistentLib.h>
void setup() {}
void loop() {}
Fix checklist
- Install the library via Library Manager
- Verify the header file name (case sensitive on some systems)
- Make sure you selected the correct board core (AVR vs ESP32 vs SAMD)
13) Arduino.h: No such file or directory or core package errors
What it means
Board core is missing/corrupted or the wrong toolchain is being used.
Fix checklist
- Re-select the board in Tools → Board
- Reinstall the board core using Boards Manager
- Restart the IDE after changes
- If using Arduino CLI, ensure the core is installed
14) “Sketch too big” / text section exceeds available space
What it means
Your compiled code (Flash usage) exceeds the board’s program memory.
Example cause
- Huge arrays not stored in Flash properly
- Many libraries included
- Debug prints and large strings
Fix strategies
- Move large constants into Flash (AVR boards):
PROGMEM - Remove unused libraries
- Reduce
Serial.printstrings, or store them more efficiently - Choose a board with more Flash (Mega, ESP32, etc.)
Example: store a long message efficiently on AVR boards:
#include <avr/pgmspace.h>
const char msg[] PROGMEM = "This is a long message stored in Flash.";
void setup() {
Serial.begin(9600);
char buf[64];
strcpy_P(buf, msg);
Serial.println(buf);
}
void loop() {}
15) low memory available, stability problems may occur
What it means
You’re close to exhausting SRAM (runtime memory). This can compile but crash later.
Fix strategies
- Reduce global arrays
- Avoid
String(dynamic allocation) - Store constants in Flash (AVR)
- Use smaller data types (
byte,uint16_t) where appropriate
Example: reduce SRAM usage
// bad (2000 bytes on Uno)
int big[1000];
// better (1000 bytes)
byte big2[1000];
16) Library conflicts and duplicate headers
Symptom
You included a library that has multiple versions installed, or two libraries provide the same header/class name.
Typical compile output clues
- “Multiple libraries were found for …”
- Odd type conflicts in headers
Fix strategies
- Remove the unused duplicate library folder
- Prefer the official library version for your board family
- Keep libraries updated consistently
17) C++ class mistakes (common with libraries)
expected initializer before ... / constructor issues
Example that fails:
class Motor {
int pin;
Motor(int p) { pin = p; } // constructor is private by default here
};
Motor m(9); // error
Fix: make constructor public
class Motor {
public:
int pin;
Motor(int p) : pin(p) {}
};
Motor m(9);
18) Macro name collisions (surprisingly common)
What it means
Some libraries or headers define macros like min, max, or round that collide.
Example that can fail in strange ways:
int max = 10; // can conflict with max() macro in some contexts
Fix: rename variables:
int maxValue = 10;
Debugging Workflow That Saves Time
- Fix the first error only, then recompile.
- If errors are huge, comment out blocks until it compiles.
- Reintroduce code chunk-by-chunk.
- If a library triggers errors, test a minimal sketch:
#include <LibraryName.h> void setup() {} void loop() {} - If a sketch compiled yesterday but fails today, suspect:
- Board selection changed
- Library updated
- IDE/toolchain updated
Mini “Error to Fix” Cheat Sheet
expected ';'→ add missing semicolonexpected '}'→ close bracesnot declared in this scope→ define in correct scope / check spellingredefinition→ remove duplicate definitionmultiple definition→externin header, define in one.cppundefined reference→ missing implementation or missing file in buildno such file or directory→ install library / correct headerno matching function→ wrong argumentssketch too big→ reduce Flash usage / change boardlow memory→ reduce SRAM usage / avoidString

