# Error fatal error: mbedtls/net.h: No such file or directory 8 | #include "mbedtls/net.h" witch Esp32

**URL:** <https://forum.arduino.cc/t/error-fatal-error-mbedtls-net-h-no-such-file-or-directory-8-include-mbedtls-net-h-witch-esp32/1374428>\
**Category:** IDE 2.x\
**Created:** [April 17, 2025, 11:57pm UTC](https://forum.arduino.cc/t/error-fatal-error-mbedtls-net-h-no-such-file-or-directory-8-include-mbedtls-net-h-witch-esp32/1374428 "2025-04-17T23:57:30Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![viniciusantonio](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/viniciusantonio/32/266835_2.png) [@viniciusantonio](https://forum.arduino.cc/u/viniciusantonio)\
**Post date:** [April 17, 2025, 11:57pm UTC](https://forum.arduino.cc/t/error-fatal-error-mbedtls-net-h-no-such-file-or-directory-8-include-mbedtls-net-h-witch-esp32/1374428/1 "2025-04-17T23:57:31Z")

</div>

Hello.

I'm trying to run a project where I'm going to send data to AWS IOT Core with an Esp32 WROOM32 but using the Arduino IDE.

One of the libraries I'm going to use is WiFiClientSecure.h. When checking a script model from this library, the following compilation error appears:

In file included from c:\Users\vinic\Documents\Arduino\libraries\WiFiClientSecure\src/WiFiClientSecure.h:26,  
from C:\Users\vinic\AppData\Local\Temp.arduinoIDE-unsaved2025317-7644-5xoi6g.b2geg\WiFiClientSecure\WiFiClientSecure.ino:9:  
c:\Users\vinic\Documents\Arduino\libraries\WiFiClientSecure\src/ssl\_client.h:8:10: fatal error: mbedtls/net.h: No such file or directory  
8 | #include "mbedtls/net.h"  
| ^ ~~~~~~~~~~~~~~  
compilation terminated.  
exit status 1

Compilation error: exit status 1

What could be causing this error?

---

<div class="post-metadata">

**Author:** ![sonofcy](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sonofcy/32/1283617_2.png) [@sonofcy](https://forum.arduino.cc/u/sonofcy)\
**Post date:** [April 18, 2025, 12:09am UTC](https://forum.arduino.cc/t/error-fatal-error-mbedtls-net-h-no-such-file-or-directory-8-include-mbedtls-net-h-witch-esp32/1374428/2 "2025-04-18T00:09:51Z")

</div>

Before anything else, read the pinned post re 'How to get the most from the forum'. That error is how we say 'missing library', which may mean that the board is not compatible, but since we can't see the code, it's difficult to know.

---

<div class="post-metadata">

**Author:** ![kenb4](https://avatars.discourse-cdn.com/v4/letter/k/bb73d2/32.png) [@kenb4](https://forum.arduino.cc/u/kenb4)\
**Post date:** [April 18, 2025, 1:01am UTC](https://forum.arduino.cc/t/error-fatal-error-mbedtls-net-h-no-such-file-or-directory-8-include-mbedtls-net-h-witch-esp32/1374428/3 "2025-04-18T01:01:31Z")

</div>

That's the old version of the library, in the wrong place.

Your `Documents/Arduino` directory is your sketchbook. The `libraries` there are for user-installed libraries, installed with the Library Manager.

`WiFiClientSecure` is already part of the ESP32 board platform. Having the extra library has confused things. Try moving the `WiFiClientSecure` folder out of the sketchbook `libraries` to somewhere not Arduino-related (`Downloads`, `Pictures`, it doesn't really matter -- or you can just delete it so it goes in the Recycle Bin, and it can be restored from there, if necessary). Then try the Verify/Compile/Upload again, with the appropriate ESP32 board selected.

(FYI, `ssl_client.h` requires `mbedtls/net.h` in the old v2 of the ESP32 board; but no longer in the current v3, which has been out for like a year.)

---

<div class="post-metadata">

**Author:** ![sonofcy](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sonofcy/32/1283617_2.png) [@sonofcy](https://forum.arduino.cc/u/sonofcy)\
**Post date:** [April 18, 2025, 1:27am UTC](https://forum.arduino.cc/t/error-fatal-error-mbedtls-net-h-no-such-file-or-directory-8-include-mbedtls-net-h-witch-esp32/1374428/4 "2025-04-18T01:27:25Z")

</div>

That explains it.

---

<div class="post-metadata">

**Author:** ![viniciusantonio](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/viniciusantonio/32/266835_2.png) [@viniciusantonio](https://forum.arduino.cc/u/viniciusantonio)\
**Post date:** [April 19, 2025, 2:13am UTC](https://forum.arduino.cc/t/error-fatal-error-mbedtls-net-h-no-such-file-or-directory-8-include-mbedtls-net-h-witch-esp32/1374428/5 "2025-04-19T02:13:02Z")

</div>

> [@kenb4](#):
>
> sketchbook

My purpose with this library is to communicate with the AWS IoT Core system. From what I understand, this library is installed in the wrong location and your suggestion is to change its directory, correct?  
First I made this change and it reported an error saying that the WiFi.h library is not in scope.  
After mentioning the WiFi.h library, there was no error when compiling.

---

<div class="post-metadata">

**Author:** ![kenb4](https://avatars.discourse-cdn.com/v4/letter/k/bb73d2/32.png) [@kenb4](https://forum.arduino.cc/u/kenb4)\
**Post date:** [April 19, 2025, 2:52am UTC](https://forum.arduino.cc/t/error-fatal-error-mbedtls-net-h-no-such-file-or-directory-8-include-mbedtls-net-h-witch-esp32/1374428/6 "2025-04-19T02:52:21Z")

</div>

`WiFiClientSecure` is already part of the ESP32 board's core platform. If you can compile and upload an empty sketch, you can use that header and the corresponding code without installing anything else.

The fact that you have another (old) copy installed (elsewhere) has confused matters. The simplest thing is to delete it. (If it gets moved to the Recycle Bin, then you should be able to get it back, if you need it for whatever reason.)

> [@](#):
>
> First I made this change and it reported an error saying that the WiFi.h library is not in scope.

I would guess the error actually said `'WiFi' was not declared in this scope`. These sorts of details matter.

> [@](#):
>
> After mentioning the WiFi.h library

You mean after `#include`-ing it?

This do-nothing sketch

```cpp
#include <WiFi.h>
#include <WiFiClientSecure.h>

WiFiClientSecure client;

void setup() {
  // put your setup code here, to run once:
  WiFi.begin("", ""); // Needs SSID and password
}

void loop() {
  // put your main code here, to run repeatedly:

}

```

should compile (and upload).

---

<div class="post-metadata">

**Author:** ![australianoz](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/australianoz/32/909046_2.png) [@australianoz](https://forum.arduino.cc/u/australianoz)\
**Post date:** [June 12, 2025, 5:56pm UTC](https://forum.arduino.cc/t/error-fatal-error-mbedtls-net-h-no-such-file-or-directory-8-include-mbedtls-net-h-witch-esp32/1374428/7 "2025-06-12T17:56:17Z")

</div>

Doesn't help much to resolve the issue though does it? Just saying, so it's regression to R2 of the ESP32 board driver I suppose. ..

I'm still in V3.0 and I too installed the incriminated library, ran thru my code at least 3 to 5 times in Verify mode (error every time), then deleted the folder as suggested by [kenb4](https://forum.arduino.cc/u/kenb4), rebooted the IDE and reran Verify; sorted.

Dunno why but it worked... and that is not good, even though i'm happy it does work.

---

<div class="post-metadata">

**Author:** ![ptillisch](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@ptillisch](https://forum.arduino.cc/u/ptillisch)\
**Post date:** [June 13, 2025, 12:00am UTC](https://forum.arduino.cc/t/error-fatal-error-mbedtls-net-h-no-such-file-or-directory-8-include-mbedtls-net-h-witch-esp32/1374428/8 "2025-06-13T00:00:02Z")

</div>

Hi @australianoz.

> [@australianoz](#):
>
> deleted the folder as suggested by [kenb4](https://forum.arduino.cc/u/kenb4), rebooted the IDE and reran Verify; sorted.
> 
> Dunno why but it worked... and that is not good, even though i'm happy it does work.

When you compile a sketch, the [Arduino sketch build system](https://arduino.github.io/arduino-cli/latest/sketch-build-process/) searches through all the installed libraries to find the ones that contain each of the header files specified by the [`#include` directives](https://www.arduino.cc/reference/en/language/structure/further-syntax/include/) in the sketch code. Multiple libraries might contain a header file with the specified filename. In this case, the sketch build system must decide which of the libraries to use.

The decision is made via [a sophisticated algorithm](https://arduino.github.io/arduino-cli/latest/sketch-build-process/#dependency-resolution), so it usually chooses the correct library, but sometimes it does get it wrong. That is what happened here. All other factors the same, the algorithm will give preference to a standalone library explicitly installed by the user over the [library incidentally installed along with the boards platform](https://arduino.github.io/arduino-cli/latest/platform-specification/#platform-bundled-libraries). So when you installed an incompatible standalone version of the library, you caused that to be used when compiling your sketch instead of the compatible version that was already present in the " **esp32**" boards platform.

In order to facilitate troubleshooting in cases like this, Arduino IDE displays a list of the matching libraries it found and which it used in the compilation output printed in the black " **Output**" panel at the bottom of Arduino IDE window. When it thinks the information is not critical, it may only show it if you have **File \> Preferences \> Show verbose output during compile** enabled. So if you're in doubt, it's a good idea to turn that option on at least for one compilation. Whenever multiple libraries were found, you will see a "`Multiple libraries were found for ...`" message in that output. Although it was a problem in this specific case, such a message is not necessarily a sign that something has gone wrong. It is a good idea to check to see whether the intended library was chosen, but otherwise you can safely ignore the message.

---

<div class="post-metadata">

**Author:** ![australianoz](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/australianoz/32/909046_2.png) [@australianoz](https://forum.arduino.cc/u/australianoz)\
**Post date:** [June 13, 2025, 6:29am UTC](https://forum.arduino.cc/t/error-fatal-error-mbedtls-net-h-no-such-file-or-directory-8-include-mbedtls-net-h-witch-esp32/1374428/9 "2025-06-13T06:29:57Z")

</div>

Well that's an explanation worth something, thanx [ptillisch](https://forum.arduino.cc/u/ptillisch). However, what I didn't mention was that before I installed the dodgy lib, my sketch never ever complied. It's only after I did the trickery and insisted that it finally compiled. Never looked back since I can now recomplile and no longer have isssues. And after many years of coding using the IDE, I've learnt today that a useful option is available... that I've now enabled, ripper.

---

<div class="post-metadata">

**Author:** ![ptillisch](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@ptillisch](https://forum.arduino.cc/u/ptillisch)\
**Post date:** [June 13, 2025, 8:50am UTC](https://forum.arduino.cc/t/error-fatal-error-mbedtls-net-h-no-such-file-or-directory-8-include-mbedtls-net-h-witch-esp32/1374428/10 "2025-06-13T08:50:43Z")

</div>

> [@australianoz](#):
>
> However, what I didn't mention was that before I installed the dodgy lib, my sketch never ever complied.

This fact does not contradict what I wrote. When Arduino IDE selects an inappropriate library, it might result in either of the two outcomes:

- compilation error
- runtime fault

The compilation error you encountered is expected in the case where the inappropriately selected library is either incompatible with the architecture of the board you are compiling for, or with the API used by the sketch being compiled.

Arduino IDE will typically show the list of candidates of library dependencies it identified, and which it selected even in cases where the compilation failed (and in fact it will show these even when the verbose compilation output is not enabled in that case).

> [@australianoz](#):
>
> I've learnt today that a useful option is available... that I've now enabled

Nice!

Although I do recommend always keeping the **Show verbose output during: ☐ upload** preference enabled, the verbose compilation output can be quite massive. So you might find that you prefer to enable **Show verbose output during: ☐ compile** only when you want to get some deeper insight into the sketch build process, such as in the case where you suspect Arduino IDE might have selected the wrong library.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [December 10, 2025, 8:50am UTC](https://forum.arduino.cc/t/error-fatal-error-mbedtls-net-h-no-such-file-or-directory-8-include-mbedtls-net-h-witch-esp32/1374428/11 "2025-12-10T08:50:45Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
