What you see
The Build tab under the code shows the compiler's own words. Click a line and the editor jumps to it. The line it names is where the compiler noticed, which is sometimes one line after the real mistake. Mokxi AI's Why won't this compile? and Fix it explain and fix the one in front of you (Mokxi AI). How building works is in code and compiling.
Find the first error in the Build tab below. Fix that one first: one mistake often causes several errors after it.
Braces, brackets and semicolons
expected ';' after expression,expected ';' at end of declaration,expected ';' after top level declarator. A line is missing its;. Add it at the end of the line named, or of the line just above it.expected ';' after struct. Astructorclassmust end with};.expected '}'. A{was opened and never closed. The missing}is usually at the end ofloop()or of anifinside it. Put the cursor next to a brace and the editor shows its match.extraneous closing brace ('}'). One}too many. Delete it.function definition is not allowed here. The function above was never closed, so this one starts inside it. Add the missing}above.expected ')'. A(is not closed. Count the brackets on that line.expected '(' after 'if'. C++ needs brackets round a condition:if (x > 5), notif x > 5.expected function body after function declarator. A header such asvoid setup()is not followed by{.
Code outside a function
expected unqualified-id. Something outside every function that C++ cannot read: a stray word, a```fence or "Copy code" pasted along with the sketch, or a line that belongs insidesetup()orloop(). Delete the stray text.a type specifier is required for all declarations,unknown type name 'Serial',while loop outside of a function. A call or a loop sits outside every function. Move it intosetup()(once) orloop()(over and over).unknown type name 'cpp'. The first line is a label copied from a chat or a web page. Delete it, and any "Copy code" line and```fences.unknown type name 'from'or'import'. The file is Python, and the sketch builds as Arduino C++. The Build tab says so first: "This sketch is MicroPython, not Arduino C++". The Raspberry Pi Pico, the Pico W and the ESP32 boards (the DevKit V1, DevKitC, LOLIN32 Lite, ESP32-S3, ESP32-C3 and ESP32-C6 boards) run MicroPython: choose MicroPython (main.py) in the board's Firmware panel and move the code tomain.py, or press Run it as MicroPython under the error to do both. A board with amain.pytab and no.inoruns MicroPython. On any other board, write the program in C++. See MicroPython on the ESP32 and the Pico.invalid preprocessing directive. A line starts with#and a word C++ does not know:#incudefor#include, say. Fix the spelling.invalid suffix 'https' on integer constant. Text pasted along with the code ended up inside a line. Delete it, or put//in front of it.
Names
undefined symbol: setup()orundefined symbol: loop(). Every sketch needs bothvoid setup() { }andvoid loop() { }, spelled exactly so, even when they are empty. An empty file gets this too.use of undeclared identifier 'serial'; did you mean 'Serial'?. Names are case sensitive. Use the spelling after "did you mean".use of undeclared identifier 'output'. Arduino constants are in capitals:OUTPUT,INPUT,INPUT_PULLUP,HIGH,LOW.use of undeclared identifier 'LED_PIN'. The name is never defined, often because the top lines of a tutorial were not copied. Addconst int LED_PIN = 13;abovesetup(). A variable bothsetup()andloop()use goes above them both.undefined symbol: blinkTwice(). A function is called but never written, is spelled differently, or was written inside another function. Write it at the top level of the sketch.redefinition of 'setup'. Two sketches pasted into one file, orsetup()in two tabs. Keep onesetup()and oneloop()and merge their bodies.redefinition of '...' as different kind of symbol. A variable has the name of something the board already has. Rename the variable.cannot combine with previous 'int' declaration specifier. Two types together, such asint int. Keep one.
Calls that do not fit
no matching function for call to 'pinMode'.pinModetakes the pin and the mode:pinMode(13, OUTPUT). A pin in quotes is text, not a number.no matching member function for call to 'println'.Serial.printlnprints one value. Print each with its ownSerial.print.no member named 'display' in .... That library has no call by that name: the sketch was written for another library or version. Built-in libraries in the code pane lists each library's calls.expression is not assignable. Something that is not a variable is on the left of=, as indigitalRead(2) = HIGH. To compare, use==.excess elements in array initializer. More values in the braces than the size in the square brackets. Leave the brackets empty:int pins[] = {2, 3, 4};member reference base type 'const char *' is not a structure or union. Plain text has no.length(). Usestrlen(text), or make it aString.
Missing files and libraries
'Something.h' file not found. Mokxi does not have that library built in. The Build tab names the built-in one that does the same job, or offers Install from the Arduino Library Manager. See the sketch does not compile.'config.h' file not found, or'secrets.h','arduino_secrets.h','credentials.h'(a name in quotes, or a settings file in angle brackets). The original project had that file as its own tab in the Arduino IDE, often with the WiFi name and password or a token kept out of the code, and it was not copied along. Add a file with that exact name to your project (the + by the tabs), or press Add a secrets.h tab under the error. The new tab has a#definewith a placeholder for each setting the sketch uses and never defines (such asSECRET_SSID,WIFI_PASSWORDorBOT_TOKEN); a WiFi name and password start as the simulated network's,Mokxi-Labandbreadboard. Put your own values in the rest. If the project has the file under another case (Secrets.h), the button changes the#includeto match instead.'WiFi.h' file not foundon a Pico, or'WiFiS3.h'on an Uno. That board has no WiFi. Pick the Pico W, an ESP32 board or the UNO R4 WiFi.This board has no simulated network in Mokxifrom a network library such asWebSocketsClient.horPubSubClient.h. That board has no WiFi. Pick an ESP32 board, the ESP8266, the Pico W or the UNO R4 WiFi.'atomic' file not foundon an Uno, Nano or Mega. The AVR boards have no C++ standard library, as on the real ones. Use avolatilevariable instead.This code is intended to run on the ESP8266 platform!. A Blynk sketch for the ESP8266 on another board. UseBlynkSimpleEsp32.hon an ESP32, orBlynkSimpleWifi.hon a Pico W. See Blynk, simulated.MIDIUSB can only be used with an USB MCU.. MIDIUSB needs a board whose chip is its own USB device: the Leonardo, the Micro or the Pro Micro. An Uno's USB is a separate chip. Pick one of those three, or send MIDI bytes on a serial port withMIDI.h. No USB host is simulated, so the MIDI messages go nowhere even there; the serial monitor says so once.A library file not found inside a library you added, such as
'OneWire_direct_regtype.h'. The project carries its own copy of a library Mokxi already has, and that copy wins. Remove it with the x on its chip in the Libraries strip under the code.enumeration values 'WStype_PING' and 'WStype_PONG' not handled in switch. A warning, not an error: the WebSockets library's examples leave some event types out of theirswitch, and the sketch still runs. Add adefault: break;to quiet it. See WiFi, simulated for what the WebSockets client can reach here.
Board limits
global variables do not fit in the 2 KB SRAM. Big arrays or long strings. Shrink them, keep text in flash withF("..."), or pick a board with more memory, such as the Mega 2560 or an ESP32.firmware does not fit in the 32 KB flash. The program is bigger than the board. Drop what the sketch does not need, or pick a bigger board.use of undeclared identifier 'Wire1'. This board has one I2C bus here: useWireand give each device its own address.use of undeclared identifier 'dacWrite'. Only the classic ESP32 has a DAC. UseanalogWrite, or pick the ESP32 DevKit.
Still stuck
Press Why won't this compile? in Mokxi AI, or write to us from /support with the error and a link to the project. See also:
- The sketch does not compile: the Build tab, libraries, and sketches that build in the Arduino IDE.
- The editor or the compiler will not load: when the build never starts.
- Arduino compile errors explained has the same messages in both GCC's words and clang's.