Fixing "No such file or directory" in Arduino
Beginner
Or see every lesson.
- 455parts on the bench
- 43boards running now
- 1.00xreal time, on every board
fatal error: DHT.h: No such file or directory means an #include line names a header file that the compiler cannot find in any folder it looks in. Usually the library that provides it is not installed, or the name in the #include is spelled differently from the file. Install the library, or correct the name, and the error goes. The error is fatal, so the build stops at the first missing header and says nothing about the lines after it.
Mokxi compiles with clang, which words it 'DHT.h' file not found. The circuit above is a DHT11 on pin 2 of an Uno, and its sketch starts with #include <DHT.h>; press Run and it prints "temperature 22 C, humidity 45 %" every two seconds. Open it, change the line to #include <DTH.h> and press Run: the build stops with 'DTH.h' file not found, and the build tab says DTH.h is not one of the libraries Mokxi has built in and offers to find it in the Arduino Library Manager.
The library is not installed
A header comes from a library, and the library has to be installed before any sketch can include it. In the Arduino IDE, open the Library Manager (Sketch, Include Library, Manage Libraries), search for the header’s name or the part, and install the library the tutorial used. DHT.h is Adafruit’s "DHT sensor library", which also needs "Adafruit Unified Sensor"; the Library Manager offers to install both.
Mokxi has the common libraries built in under their usual names, so DHT.h, Servo.h, LiquidCrystal_I2C.h, Adafruit_SSD1306.h, ArduinoJson.h, FastLED.h and Keypad.h all built as they are on an Uno. Built-in libraries, in the code pane, lists every one. For a header it does not have, the build tab says "Install it from the Arduino Library Manager (Install, or the Arduino Library Manager search under the code), or use Add library to upload its .zip or its .h and .cpp files".
Because the error is fatal, a sketch that includes two missing headers reports only the first. A sketch with #include <NoSuchLib.h> and #include <OtherLib.h> stopped with one error, about NoSuchLib.h; install that one and the next appears.
The name is spelled differently from the file
The #include has to name the file, not the library. The library "LiquidCrystal I2C" has the header LiquidCrystal_I2C.h, with an underscore: #include <LiquidCrystal I2C.h> is not found, and neither is #include <LiquidCrystal_I2C> without the .h. Open the library’s own example (File, Examples in the IDE) and copy its #include line.
Capital letters depend on the computer. On Linux, file names are case sensitive and servo.h is not Servo.h; Windows and macOS usually find the file either way, which is why a sketch can build on one computer and fail on another. Mokxi finds servo.h, dht.h and wire.h as Servo.h, DHT.h and Wire.h, but write them the way the library does, so the sketch builds everywhere.
The header belongs to another board
Some headers come with a board’s core, not with a library, and exist only for that board. WiFi.h and HTTPClient.h belong to the ESP32 boards, ESP8266WiFi.h to the ESP8266, and avr/io.h to the AVR chips of the Uno, Nano and Mega. Include one on a board that does not have it and it is not found, however many libraries are installed. In the Arduino IDE, pick the board the sketch was written for (Tools, Board), after adding its board package in the Boards Manager.
In Mokxi the board in the circuit is the board the code is built for, and the build tab names the boards a header is for. #include <WiFi.h> on an Uno said WiFi "is in Mokxi for the ESP32-C3, the ESP32-C6" and fifteen more boards, "and not for the Arduino Uno". A few headers stop the build with their own message instead: ESP8266WiFi.h on an Uno says "This board has no simulated network in Mokxi", and SoftwareSerial.h on an ESP32-C3 says it "is for the AVR boards (Uno, Nano, Pro Mini, Mega, Leonardo, Pro Micro), the ESP8266, the ESP32 and the ESP32-S3 in Mokxi".
Quotes or angle brackets
#include <DHT.h>, with angle brackets, looks in the installed libraries and the core. #include "config.h", with quotes, looks in the sketch’s own folder first and then in the same places. Quotes are for a file that is a tab of the sketch, such as the config.h or arduino_secrets.h that some examples keep their settings in. When that tab was not copied along with the sketch, the include fails, and Mokxi’s build tab says "This project has no file named config.h, which this line includes" and asks for a new tab with that name.
A library in quotes still works, because the search goes on to the libraries: #include "Servo.h" built on an Uno. Angle brackets for libraries and quotes for your own tabs is the usual style, and it tells the next reader where to look.
Arduino.h not found outside the Arduino IDE
fatal error: Arduino.h: No such file or directory in PlatformIO or ESPHome means the project is not set up to build with the Arduino core at all. In PlatformIO, the line framework = arduino in platformio.ini is what brings it in. In the Arduino IDE and in Mokxi the core is always there.
Questions
How do I fix "DHT.h: No such file or directory"?
Install Adafruit’s "DHT sensor library" from the Library Manager, and "Adafruit Unified Sensor" when the IDE asks. In Mokxi, DHT.h is built in.
How do I fix "LiquidCrystal_I2C.h: No such file or directory"?
Install a LiquidCrystal I2C library from the Library Manager, and check that the #include is spelled LiquidCrystal_I2C.h, with the underscore and the .h. In Mokxi it is built in.
Is "file not found" the same error?
Yes. It is clang’s wording; GCC, which the Arduino IDE uses, says "No such file or directory". Mokxi compiles with clang, so its build tab shows clang’s words.
Why does it only complain about one header when two are missing?
A missing header is a fatal error, so the build stops there. Fix that one, build again, and the next one shows.
Keep going
Build this for real
Open the editor, change a value and watch the number move with it. Nothing to install, and no account needed.