Using SdFat.h together with ESP8266WiFi.h -> reference to 'File' is ambiguous

Hi guys,

For a school project we are trying to create a project that both uses an sdcard reader and the built in wifi of the Wemos D1 mini. We have created code for reading files from the sd card which seems to be working fine, and we have found code to use the wifi to get the current time (which is only one of the things we will be using the wifi for) which is also working fine. But as soon as we try to combine the two programs we run into problems :frowning:

The main problem seems to be between the used includes, as soon as we try to include both SdFat.h and ESP8266WiFi.h, it does not matter what kind of program we perform further (even just blink won't work) as soon as we include both we get that an error has occured compiling for our board.

It seems to be a problem with both having a definition for File.

Does anybody know how to solve this or if we could use similar libraries with the same functionalities without the problem?

Any help would be greatly appreciated :slight_smile:

Sample code, this is just doing some read and write using sdfat with the esp8266wifi included

#include <SdFat.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
#include <ESP8266WiFi.h>

using namespace sdfat;

SdFat sd;

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(115200);
  Serial.println("Initializing SD card...");

  sd.begin(D8);

  Serial.println("initialization succeeded");
  File dataFile = sd.open("test.txt", FILE_WRITE);
  if (dataFile){
    Serial.println("writing to file");
    dataFile.println("hello we are just testing here");
    dataFile.close();
    Serial.println("writing succeeded, closing file");
  }
  Serial.println("finished");
  File outFile = sd.open("test.txt");
  Serial.println("testing output");
  while(outFile.available())
    Serial.write(outFile.read());
    
  outFile.close();
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, LOW);   // Turn the LED on (Note that LOW is the voltage level
  // but actually the LED is on; this is because
  // it is active low on the ESP-01)
  delay(1000);                      // Wait for a second
  digitalWrite(LED_BUILTIN, HIGH);  // Turn the LED off by making the voltage HIGH
  delay(2000);                      // Wait for two seconds (to demonstrate the active low LED)
}

And top part of the error messages as most of it below seems causes by those

C:\Users\Niek\Documents\Arduino\testSDCard\testSDCard.ino: In function 'void setup()':

testSDCard:18:3: error: reference to 'File' is ambiguous

   File dataFile = sd.open("test.txt", FILE_WRITE);

   ^

In file included from C:\Users\Niek\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.6.3\libraries\ESP8266WiFi\src/CertStoreBearSSL.h:26:0,

                 from C:\Users\Niek\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.6.3\libraries\ESP8266WiFi\src/WiFiClientSecureBearSSL.h:30,

                 from C:\Users\Niek\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.6.3\libraries\ESP8266WiFi\src/WiFiClientSecure.h:41,

                 from C:\Users\Niek\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.6.3\libraries\ESP8266WiFi\src/WiFiServerSecure.h:20,

                 from C:\Users\Niek\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.6.3\libraries\ESP8266WiFi\src/ESP8266WiFi.h:41,

                 from C:\Users\Niek\Documents\Arduino\testSDCard\testSDCard.ino:4:

C:\Users\Niek\Documents\ArduinoData\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\Niek\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.6.3\libraries\ESP8266SdFat\src/FatLib/FatLib.h:27:0,

                 from C:\Users\Niek\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.6.3\libraries\ESP8266SdFat\src/SdFat.h:33,

                 from C:\Users\Niek\Documents\Arduino\testSDCard\testSDCard.ino:1:

C:\Users\Niek\Documents\ArduinoData\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 {

       ^

testSDCard:18:8: error: expected ';' before 'dataFile'

   File dataFile = sd.open("test.txt", FILE_WRITE);

        ^

testSDCard:19:7: error: 'dataFile' was not declared in this scope

   if (dataFile){

       ^

testSDCard:26:3: error: reference to 'File' is ambiguous

   File outFile = sd.open("test.txt");

   ^
xFile dataFile = sd.open("test.txt", FILE_WRITE);

One of the libraries, most likely, has a File declared.

Found a fix (at least for now, hope it won't turn into new problems)

had to change all occurences of File in the sdfat library into something else (I chose SDFile)
changed files are: FatFileSystem.h and ArduinoFiles.h