“.h: No such file or directory” – 2 Easy fixes to Arduino error
It’s 11 PM on a Wednesday. You’ve just spent three hours toiling on your next Arduino project, and FINALLY, you’re ready to give your sketch a whirl. You hit upload, palms sweaty with anticipation to see all your hard work come to fruition. It’s then you see the error:
No such file or directory.
Surely this is a chance aberration. “Nothing to worry about,” you mutter, sleep-starved and semi-delirious as you hit upload again. And once more, those maddening words, “no such file or directory,” stare back at you in hostile gaslighting mockery.
Have you been here?
If you’re trying to run an Arduino sketch but keep coming across the “no such file or directory” error, don’t worry. This is actually a pretty common problem, and there are two easy fixes that almost always work.
Keep on reading. We’ll show you what they are.
No such file error!
Error messages can be such a pain. They do, however, serve a useful purpose by telling us something about what went wrong. At first glance, the no such file or directory error is particularly maddening because it seems to break that useful purpose rule. Of course there’s a file or directory! You just made the thing, and it’s right there, tucked inside a directory.
But hold up, let’s take a closer look. If you look at the bottom portion of the Arduino IDE where the error message shows up, there’s this handy little button that says “copy error messages.”
Click on that now. You probably won’t fall off your chair to learn that by clicking that button, you just copied the error message from the little window at the bottom of The Serial Monitor’s UI to the clipboard of your computer.
This copy feature is ridiculously useful. You could, for example, paste the error message into Google and learn more about the error. Or you could take advantage of the active Arduino community by asking for help in a forum. For this situation, however, we can be a bit more basic. All we’re going to do is take a closer look at what the message is actually saying. To do that, just fire up your PC’s text editor and paste it into the blank screen.
Programming Electronics Academy members, learn about the Arduino IDE toolchain in the Familiarization section of the Arduino Course for Absolute Beginners.
Not a member yet? Sign up here.
Decoding the no such file error
Here it is, that pesky error in all its freshly pasted glory.
I’ll break it down for you line by line.
- The first line is easy. It’s just describing the Arduino version in use, what operating system is running, and which board you have selected.
- Line 2 begins to zero in on the problem.
- The first bit, “knob,” is referring to the name of the program. This is your sketch, basically.
- The second bit is what usually begins to confuse people, but it’s easy once you know. The “10” in this example is telling you the error occurred on line 10 of your sketch. The “19” is telling you the length of the line of code in spaces and characters. The first number is usually the more helpful of the two because you can use it to locate the error in your sketch.
- Then we get to the smoking gun of the error. It says, “servo.h: No such file or directory”.
So this thing, “Servo.h.” That’s the thing we need to fix, and thanks to line 2, we know where to find it. Line 10. It’s always line 10.
Now that we know what’s going on a bit better, let’s get down to the business of implementing a fix.
The error of our ways
Let’s lay down some scrutiny on this accursed line 10.
It says “#include <servo.h>”
When we verify this code, this line is telling the Arduino IDE compiler, “Hey, for this program to work, you need to go get this file called servo.h”.
Let’s say you had a label-making machine, and you wanted to use it to print some cool motivational labels, like “Success!” and “Keep Trying!” and “Look, Nachos!” To make that happen, you’ll first have to load in a roll of labels. No roll of labels? Well, then the label maker isn’t gonna work.
The sketch you’re trying to upload is like the label maker. The file (in our example, the file named “servo.h”) is the roll of labels.
So the error message actually is saying something useful. It’s saying, “Hey programmer, you said I needed this other file. Well, I looked for it and it’s not there. What gives?”
Now we know the error message isn’t complete gibberish, let’s look at the two most common scenarios that cause it.
Programming Electronics Academy members, learn how to choose, install, and use Arduino libraries in the Arduino Course for Absolute Beginners Code Libraries section.
Not a member yet? Sign up here.
Scenario 1 – Fat fingers
This sketch is one that you’ve written. You’re actually the one who wrote the “#include” line. The first thing you should check is your spelling and capitalization. Maybe you spelled the name of the library incorrectly? Or (as with the example below) perhaps you capitalized the wrong letters.
So “servo.h” should actually have a capital “S.” In full and with correct capitalization, it should read, “Servo.h.” You’ll notice above that the word servo changes color when it’s correctly capitalized. That color change signifies that the library name “Servo” is recognized as a “keyword” in the Arduino IDE.
Keep in mind that might not be the case for all the libraries you’re using. In other words, the color change won’t always indicate you’re using the right spelling or capitalization, but it’s often a helpful visual reminder.
Oh, and it’s probably good to mention that everyone in the history of Arduino programming has misspelled or incorrectly capitalized a word at some point. It’s amazing how long you can stare at a line of code and miss something like that.
So don’t sweat it.
Scenario 2 – Missing files
This brings us to the next common scenario for the “no such file or directory” error.
So often, working with Arduinos involves taking code that someone else has developed and shared online and then tailoring it to your project. That’s part of what makes it so easy to get stuff done with Arduino. One problem that frequently happens when we do that, however, is we accidentally introduce code without a matching file.
An easy way to check to see if you have the file a sketch is looking for is to navigate to Sketch > Include Library from within the Arduino IDE. Then look for the name of that library.
Whatever library the #include statement was calling for, you want to look through this big long list for a library with the exact same name. If you don’t see the file name there, this means the library isn’t installed. You’ll have to add that library before the sketch will compile without errors.
So, how do you add that library?
The easiest way is to go to Sketch > Include Library > Manage Libraries. The Arduino IDE will open up a dialogue box from which you can search for the library you need.
Make sure you type the exact word that matches the #include line. Once you find the missing library, go ahead and click Install. The Arduino IDE will let you know that it’s installing the library you requested and updating the software accordingly.
Next, just double-check that the library has been successfully installed by going to Sketch > Include Library. You should see your new library in the dropdown list.
Good news! If the library is there, you should now be able to compile your sketch error-free.
Other library locations
OK, there’s one little fly in the ointment. How do these dang ointment flies always manage to complicate things so?
Here’s the thing. Not all libraries live in this convenient pop-up window inside the Arduino IDE. The Arduino community is bubbling with clever ideas, but cleverness (unlike processed cheese) doesn’t always come in conveniently standardized, individually wrapped slices. There are tons of different ways to find Arduino libraries on the web.
If you’re downloading or copying a program from the internet, just go to the page where you got that program and take a close look at the library the author is referencing. They may, for example, have a link to GitHub, which is a place where people keep a lot of code libraries.
Wherever you find it, usually the library will be included in a .zip file package. Once you’ve downloaded the .zip file, fire up the Arduino IDE and go to Sketch > Include Library > Add .ZIP library. Then navigate to the location you downloaded the file and select it. Assuming no additional ointment flies invade your workflow, the Arduino IDE will pop up the message “Library added to your libraries” just above the dark area where the original “no such file or directory” error appeared.
Now it’s business as usual! Just go to Sketch > Include Library, and the new library will appear in the drop-down list.
As the dyslexic Frenchman once said to the oversized violinist: “Viola!”
You now know not one but two ways to add a new library. What a time to be alive!
Programming Electronics Academy members, check out the Arduino Course for Absolute Beginners to jump start your Arduino programming skills.
Not a member yet? Sign up here.
Review
A quick recap, then.
We’ve looked at the two main scenarios that cause the “no such file or directory” error to appear after you compile your sketch:
- The fat fingers phenomenon: Check your spelling and capitalization! If you wrote the sketch, there’s a mighty good chance you introduced a tiny error. And don’t beat yourself up over it! Literally every coder has done this.
- The missing files mixup: Failing that, if you copied code from someone else check that you have the correct libraries installed. Don’t see your library? Install it using the method described above, and you should be good to go.
There may be no such thing as a free lunch, a coincidence, or a luck dragon. But rest assured. Your files and directories? They’re alive and well.
Great video showing how to include libraries and search libraries if you don’t see a library in your sketch book.
Please keep up the great work. Making Arduino code writing easier.
Thanks,
Jack Brockhurst
Thanks Jack! We’ll do our best to keep them coming.
Thank you for the information, this is very helpful
Great tips! thanks for the tutorials.
Thanks Daniel! I am glad it was helpful.
great explanation
Thanks Venkat!
Tutorials are very comprehensive! Thanks!!
Thank you Juven! I am glad they helped!
Very clear and helpfull
Thanks ! !
Hi, I have the same problem: no such file or directory when trying to run ‘Keypad’, so I noticed it wasn’t written in orange.
I see that I didn’t have it in my library (closest thing was Keyboard) so I went to the library manager and downloaded it.
This time it’s in orange, ran the code again, same message. (?!?)
Tried to put the code in by clicking on it from the Sketch –> Include etc, and a weird thing happens: first row: #include written in black, and second row: #include written in orange.
I’m trying to use it for a 4×4 keypad
Same. Did you find the fix already?
lcd.setCursor(0,1);
lcd.print(“QUALITY MONITOR”);
delay(3000);
// pinMode(12, INPUT);
// reset ESP8266 WiFi connection AT+CIPMUX=1 AT+CWJAP
ser.println(“AT”);
delay(1000);
ser.println(“AT+GMR”);
delay(1000);
ser.println(“AT+CWMODE=3”);
delay(1000);
ser.println(“AT+RST”);
delay(5000);
ser.println(“AT+CIPMUX=1″);
delay(1000);
String cmd=”AT+CWJAP=”, EngineersGarage “,”01234567672″”;
ser.println(cmd);
delay(1000);
ser.println(“AT+CIFSR”);
delay(1000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(” WIFI”);
lcd.setCursor(0,1);
lcd.print(” CONNECTED”);
}
// the loop
void loop()
{
delay(1000);
t = analogRead(A0);
Serial.print(“Airquality = “);
Serial.println(t);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(” SENDING DATA”);
lcd.setCursor(0,1);
lcd.print(” TO CLOUD”);
esp_8266();
}
void esp_8266()
{
// TCP connection AT+CIPSTART=4,”TCP”,”184.106.153.149″,80
String cmd = “AT+CIPSTART=4,\”TCP\”,\””;
cmd += “184.106.153.149”; // api.thingspeak.com
cmd += “\”,80″;
ser.println(cmd);
Serial.println(cmd);
if(ser.find(“Error”))
{
Serial.println(“AT+CIPSTART error”);
return;
}
// prepare GET string GET https://api.thingspeak.com/update?api_key=;field1=0rnrn
String getStr = “GET /update?api_key=”;
getStr += apiKey;
//getStr +=”&field1=”;
//getStr +=String(h);
getStr +=”&field1=”;
getStr +=String(t);
getStr += “rnrn”;
// send data length
cmd = “AT+CIPSEND=4,”;
cmd += String(getStr.length());
ser.println(cmd);
Serial.println(cmd);
delay(1000);
ser.print(getStr);
Serial.println(getStr);
// thingspeak needs 15 sec delay between updates
delay(16000);
}
=>
in this program i got an error expected initializer before string constant
Liquid crystal _I2C.h :No such file or directory
Did all thibg but it is not happening
Arduino: 1.8.15 (Mac OS X), Board: “Arduino Uno”
Multiple libraries were found for “Usb.h”
checkm8-a5:4:10: fatal error: Constants.h: No such file or directory
Used: /Users/sana/Documents/Arduino/libraries/USB_Host_Shield_2.0
#include “Constants.h”
^~~~~~~~~~~~~
compilation terminated.
Not used: /Users/sana/Documents/Arduino/libraries/USB_Host_Shield_Library_2.0
Not used: /Users/sana/Documents/Arduino/libraries/USBHost
exit status 1
Constants.h: No such file or directory
This report would have more information with
“Show verbose output during compilation”
option enabled in File -> Preferences.
Looks like you may not have your Constants.h file in your sketch folder?
hi, ive got checkm8 and ive got constants.h in the library, so idk
Bonjour,
j’ai suivi la démarche a la lettre mais je ne suis pas arrivé
a trouver la bibliothèque RFID.
avez vous une idée ou je peux la trouver
merci
I followed the process to the letter but I did not arrive
find the RFID library.
do you have an idea where i can find it
thank you
Is there a specific RFID library you are working with? Do you have a link to its GitHub repo by chance?
Michael,
I am having trouble with the Radiohead RFM95 encrypted client example, seems Speck.h shows as no such file or directory. I can find code for Speck.h but not as a file I can drop in my library. I imagine there is a way to create the right file type in VS but I am not familiar with how to do that, assuming that would even do the trick. I would appreciate a little help here as I am rather new to Arduino and C++.
Here is the sample library:
// LoRa Simple Hello World Client with encrypted communications
// In order for this to compile you MUST uncomment the #define RH_ENABLE_ENCRYPTION_MODULE line
// at the bottom of RadioHead.h, AND you MUST have installed the Crypto directory from arduinolibs:
// http://rweather.github.io/arduinolibs/index.html
// Philippe.Rochat’at’gmail.com
// 06.07.2017
#include
#include
#include
RH_RF95 rf95; // Instanciate a LoRa driver
Speck myCipher; // Instanciate a Speck block ciphering
RHEncryptedDriver myDriver(rf95, myCipher); // Instantiate the driver with those two
float frequency = 868.0; // Change the frequency here.
unsigned char encryptkey[16] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}; // The very secret key
char HWMessage[] = “Hello World ! I’m happy if you can read me”;
uint8_t HWMessageLen;
void setup()
{
HWMessageLen = strlen(HWMessage);
Serial.begin(9600);
while (!Serial) ; // Wait for serial port to be available
Serial.println(“LoRa Simple_Encrypted Client”);
if (!rf95.init())
Serial.println(“LoRa init failed”);
// Setup ISM frequency
rf95.setFrequency(frequency);
// Setup Power,dBm
rf95.setTxPower(13);
myCipher.setKey(encryptkey, sizeof(encryptkey));
Serial.println(“Waiting for radio to setup”);
delay(1000);
Serial.println(“Setup completed”);
}
void loop()
{
uint8_t data[HWMessageLen+1] = {0};
for(uint8_t i = 0; i<= HWMessageLen; i++) data[i] = (uint8_t)HWMessage[i];
myDriver.send(data, sizeof(data)); // Send out ID + Sensor data to LoRa gateway
Serial.print("Sent: ");
Serial.println((char *)&data);
delay(4000);
}
Here is Speck.h:
/*
* Copyright (C) 2015 Southern Storm Software, Pty Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef CRYPTO_SPECK_H
#define CRYPTO_SPECK_H
#include "BlockCipher.h"
class Speck : public BlockCipher
public:
Speck();
virtual ~Speck();
size_t blockSize() const;
size_t keySize() const;
bool setKey(const uint8_t *key, size_t len);
void encryptBlock(uint8_t *output, const uint8_t *input);
void decryptBlock(uint8_t *output, const uint8_t *input);
void clear();
private:
uint64_t k[34];
uint8_t rounds;
};
#endif
Here is BlockCipher.h:
/*
* Copyright (C) 2015 Southern Storm Software, Pty Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef CRYPTO_BLOCKCIPHER_h
#define CRYPTO_BLOCKCIPHER_h
#include
#include
class BlockCipher
{
public:
BlockCipher();
virtual ~BlockCipher();
virtual size_t blockSize() const = 0;
virtual size_t keySize() const = 0;
virtual bool setKey(const uint8_t *key, size_t len) = 0;
virtual void encryptBlock(uint8_t *output, const uint8_t *input) = 0;
virtual void decryptBlock(uint8_t *output, const uint8_t *input) = 0;
virtual void clear() = 0;
};
#endif
Interesting one!
OK, here is what I did to get it compiling.
I went here: https://github.com/kostko/arduino-crypto
And downloaded that library, unzipped it into my Arduino/libraries folder, and renamed the enclosing folder to from arduino-crypto-master to just Crypto.
(the Arduino IDE library manager gave me a different library than that it seems – which didn’t have the Speck.h file)
Then, as per the comments in your sketch, I uncommented that line in the RadioHead.h file (it was like ALL the way at the bottom – a couple lines up)
Then I was able to verify this sketch ok.
sketch_oct15a:5:31: fatal error: LiquidCrystal_I2C.h: No such file or directory
#include
compilation terminated.
exit status 1
LiquidCrystal_I2C.h: No such file or directory
Sir I am facing this problem whenever I am trying to upload this program – Arduino 1.8.19 with “NodeMCU 1.0(ESP-12E Module)”-ESP8266 Boards (2.5.2)
Have you installed the LiquidCrystal_I2C library?
To install it, in the Arduino IDE you would go to “Tools > Manage Libraries” and then search for that library and click install.
I still have this error! I did 10-check, and nothing! Keypad.h is orange, it’s like Arduino sees it, but NO! I have this error:
Arduino: 1.8.12 (Windows 10), Board: “Arduino Uno”
swanky_juttuli1:1:10: fatal error: Keypad.h: No such file or directory
#include
^~~~~~~~~~
compilation terminated.
exit status 1
Keypad.h: No such file or directory
This report would have more information with
“Show verbose output during compilation”
option enabled in File -> Preferences.
Help me please.
Hmmm – do you have multiple keypad libraries installed?
I’ve got a error message like this:
C:\Users\Chenh\AppData\Local\Temp\.arduinoIDE-unsaved202314-14908-oujzau.jivff\RomiRPiSlaveDemo\RomiRPiSlaveDemo.ino:1:10: fatal error: Romi32U4.h: No such file or directory
#include
^~~~~~~~~~~~
compilation terminated.
exit status 1
Compilation error: Romi32U4.h: No such file or directory
I have the library installed and the spelling is correct. I just don’t know why Arduino still can’t find it & why it’s looking for the libraries in a Temp folder.
When you go to File > Settings, what is the file path selected as your Sketchbook folder? Usually (by default) it’s best to have it located under Documents > Arduino. Inside the Arduino folder, there should be another folder named libraires, where the IDE will save and look for installed Arduino libraries.
Thank you very very Mutch ; helpful vedeo
Glad it helped!
Thank you for the information, this is very helpful
I saw TM1637Display.h library in sketch -> include library,
correctly declared #include ,
the file path is in Documents -> Arduino. but still shows error:
“C:\Users\abc12\OneDrive\Documents\Arduino\den_Giao_thong\den_Giao_thong.ino:1:10: fatal error: TM1637Display.h: No such file or directory
compilation terminated.
exit status 1
Compilation error: TM1637Display.h: No such file or directory”
when compiling the program
Tuan, Do you have the library installed?