Arduino

How to fix .h: No such file or directory error

In Arduino programming when writing a code for the microcontroller to perform some specific task one should expect that there might be some errors at the time of compilation of the Arduino code. We can classify the errors encountered while writing the Arduino code; some are related to the syntax; some are related to the declaration of variables or libraries; and all these errors come under the compiler errors. Although the Arduino IDE indicates the expected errors before compiling the code by highlighting the lines having the error in the red. Similarly, when the code is compiled, and a specific error is raised the compiler tells which thing in that line is causing that specific error. So, in this write up we have discussed an error that is “no such file or directory” in detail.

What is the “no such file or directory” error and how does this error occur

From the name of the error, it is obvious that when a file name being used in the Arduino code is not present in the installed directory of the Arduino IDE this error can be encountered. This error relates to the libraries we use to interface different devices with Arduino boards. When we compile the respective code using the library of any device the compiler searches that specific library in its installed directory. If it is unable to find such a file it gives the respective error of “no such file or directory “. The libraries are used for helping the compiler to know about the functions that we are going to perform using that device by interfacing it with the Arduino board.

How resolve the error “no such file or directory”

To give the clear concept of the error we have explained it with the help of code compiled for interfacing the keypad with Arduino. The code for interfacing the keypad with Arduino is given below in the figure and you can see in the figure that it is highlighted in red and when we compile the code, we get the error “no such file or directory”:

To resolve the error “no such file or directory” we have to install the respective library in order to compile the code successfully.

For installing the library of the keypad we have given the image below that shows step wise installation of the library for the keypad. You can use the similar procedure for installing the library for any device; the only change will be the key word used in the search bar of the library manager.

1 : To install the library we have to access the library manager of the Arduino IDE by pressing the library icon that comes fourth in the menu that you can see on the left of the compiler.

2 : Next after opening the library manager you have to write the name of the device that you are interfacing with Arduino and the list of libraries will appear.

3 : As in our case the device is a keypad. We wrote the keypad in the search bar and after that found the suitable library for the keypad.

4 : Once you have found the suitable library, click the icon colored in blue having INSTALL written on it for installing the library.

After the library is installed, you will see its status in the output menu at the bottom as well as shown in the figure given below:

Now as you can see in the image below that the code is successfully compiled and the error of “ no such file or directory “ is removed.

Conclusion

There are different types of errors that can be encountered while compiling the Arduino code. The errors might be related to the syntax or related to the declaration of variables and libraries. The use of libraries gives the compiler an idea of which functions are to be performed using a specific device. Sometimes the Arduino IDE does not have the libraries for some devices and when the code is compiled it gives the error “no such file or directory “as the compiler is unable to recognize the functions. So, in this write-up we have explained how we can remove the Arduino IDE error that is “no such file or directory”.

About the author

Aaliyan Javaid

I am an electrical engineer and a technical blogger. My keen interest in embedded systems has led me to write and share my knowledge about them.