Reference to "File" is ambiguous


I’ve gotten myself an ESP8266 (WiFi Mini ESP8266 Main Board | Jaycar Electronics) and have been messing around with it. But I’ve come across an issue.

My latest project (And so far only project) regarding the ESP8266 is a bit of a complex one. I connect my phone to it in WIFI_AP mode, and it receives terminal data from my phone. This works fine. Then I try to talk to a microSD card. This also works fine. However, I’ve noted that when I try to merge the two projects (Look up a code on the microSD that the phone gives it), I am having a “Reference to “File” is ambiguous” error.

I seem to have made an example of the problem with a simple enough script:

#include <ESP8266WiFi.h>
#include <SPI.h>
#include "SdFat.h"

using namespace sdfat;

extern "C" {

SdFat sd;
SdFile root;
SdFile file;

File f;

void setup() {}
void loop() {}

And the error:

Arduino: 1.8.12 (Windows 10), Board: "Generic ESP8266 Module, 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), dtr (aka nodemcu), 26 MHz, 40MHz, DOUT (compatible), 1MB (FS:64KB OTA:~470KB), 2, nonos-sdk 2.2.1+100 (190703), v2 Lower Memory, Disabled, None, Only Sketch, 115200"

Warning: Board breadboard:avr:atmega328bb doesn't define a 'build.board' preference. Auto-set to: AVR_ATMEGA328BB
sketch_apr26f:15:1: error: reference to 'File' is ambiguous

 File f;


In file included from C:\Users\aj200\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\libraries\ESP8266WiFi\src/CertStoreBearSSL.h:26:0,

                 from C:\Users\aj200\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\libraries\ESP8266WiFi\src/WiFiClientSecureBearSSL.h:30,

                 from C:\Users\aj200\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\libraries\ESP8266WiFi\src/WiFiClientSecure.h:41,

                 from C:\Users\aj200\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\libraries\ESP8266WiFi\src/WiFiServerSecure.h:20,

                 from C:\Users\aj200\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\libraries\ESP8266WiFi\src/ESP8266WiFi.h:41,

                 from C:\Users\aj200\AppData\Local\Temp\arduino_modified_sketch_798268\sketch_apr26f.ino:1:

C:\Users\aj200\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\cores\esp8266/FS.h:52:7: note: candidates are: class fs::File

 class File : public Stream


In file included from C:\Users\aj200\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\libraries\ESP8266SdFat\src/FatLib/FatLib.h:27:0,

                 from C:\Users\aj200\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\libraries\ESP8266SdFat\src/SdFat.h:33,

                 from C:\Users\aj200\AppData\Local\Temp\arduino_modified_sketch_798268\sketch_apr26f.ino:3:

C:\Users\aj200\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\libraries\ESP8266SdFat\src/FatLib/ArduinoFiles.h:125:7: note:                 class sdfat::File

 class File : public FatFile, public Stream {


sketch_apr26f:15:1: error: 'File' does not name a type

 File f;


exit status 1
reference to 'File' is ambiguous

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

What seems to happen is that the two libraries I’m using both have a definition for “File”. I need to use both, and I have no idea how to solve this issue. I note that I am making an “SdFile” object, but I have just copied this from another script that DOES work (No “#include <ESP8266WiFi.h>” line).

Option 1: Does anyone know of a simple way to solve this? I know that some other languages allow you to pick WHICH library to use, such as typing “SdFat.File f;”. I was wondering if arduino had something similiar.

Option 2: Does anyone know of an SD library that is functionally identical to the Arduino default library but has a different name to avoid conflict?

Option 3: Does anyone know how to edit the “ESP8266WiFi.h” file to stop this conflict (No preferable)

Option 4: (As annoying as I know it is to ask) Could anyone explain how to use SdFile or point me to some documentation? The only documentation I could find is on the standard “SD” library, which seems to be quite different (And apparently slower, although that isn’t an issue for the current project).

Ultimately, everything else is fine. The only thing I need to solve is the “File” object. If I have to dissect the arduino code, find where the “File” object in SdFat is located, and make a modified copy of it with a different name in it’s own library to avoid conflict, I will.

Thanking you all in advance,

What seems to happen is that the two libraries I’m using both have a definition for “File”.


If I have to dissect the arduino code, find where the “File” object in SdFat is located, and make a modified copy of it in it’s own library, I will.

I don’t see how creating a 3rd definition of File will help.

I completely forgot to explain how I fixed this error, sorry. Ok, to fix it, you can use both libraries, but you need to edit a couple of them. If anyone has this exact issue, be it tomorrow, next week, or 6 years after this thread, I'd be happy to supply the modified and functioning ESP8266 libraries that allow for SD card communication AND Wifi communication at the same time!

This was NOT a trivial problem as it turned out, and most of the issues were surrounding the FS library that was creating a global variable called "File", leading to the error. You can actually mute the issue by defining a couple things, thereby stopping the library from making it's variables global

1 Month and 3 days :slight_smile:

I have the same kit from JayCar, and receiving the ambiguous type issue. As a C# developer by trade you can easily fully qualify but I don't know how to in C.

My preference would have been to not modify libraries, but would appreciate some help!

EDIT: I worked out how to fully qualify the ambiguous type without having to modify the libraries!

 sdfat::File outputFile ="/test.csv", FILE_WRITE);

Oh! I tried that and it didn't work on my end, hence modifying all the libraries. I think I only did a single colon instead of the double. That saves so much time!