Troubleshooting

Build errors in plain words

The compiler messages people meet most in Mokxi, what each one means, and what to change.

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. A struct or class must end with };.
  • expected '}'. A { was opened and never closed. The missing } is usually at the end of loop() or of an if inside 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), not if x > 5.
  • expected function body after function declarator. A header such as void 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 inside setup() or loop(). 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 into setup() (once) or loop() (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 to main.py, or press Run it as MicroPython under the error to do both. A board with a main.py tab and no .ino runs 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: #incude for #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() or undefined symbol: loop(). Every sketch needs both void setup() { } and void 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. Add const int LED_PIN = 13; above setup(). A variable both setup() and loop() 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, or setup() in two tabs. Keep one setup() and one loop() 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 as int int. Keep one.

Calls that do not fit

  • no matching function for call to 'pinMode'. pinMode takes 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.println prints one value. Print each with its own Serial.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 in digitalRead(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(). Use strlen(text), or make it a String.

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 #define with a placeholder for each setting the sketch uses and never defines (such as SECRET_SSID, WIFI_PASSWORD or BOT_TOKEN); a WiFi name and password start as the simulated network's, Mokxi-Lab and breadboard. Put your own values in the rest. If the project has the file under another case (Secrets.h), the button changes the #include to match instead.

  • 'WiFi.h' file not found on 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 Mokxi from a network library such as WebSocketsClient.h or PubSubClient.h. That board has no WiFi. Pick an ESP32 board, the ESP8266, the Pico W or the UNO R4 WiFi.

  • 'atomic' file not found on an Uno, Nano or Mega. The AVR boards have no C++ standard library, as on the real ones. Use a volatile variable instead.

  • This code is intended to run on the ESP8266 platform!. A Blynk sketch for the ESP8266 on another board. Use BlynkSimpleEsp32.h on an ESP32, or BlynkSimpleWifi.h on 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 with MIDI.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 their switch, and the sketch still runs. Add a default: 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 with F("..."), 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: use Wire and give each device its own address.
  • use of undeclared identifier 'dacWrite'. Only the classic ESP32 has a DAC. Use analogWrite, 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: