T-Display: Including TFT_eSPI.h introduces a compile error

Firstly apologies if this is a duplicate or known problem. I have had a search and read the suggested similar issues but haven't found a match.

I am using a LilyGo T-Display S3 AMOLED, with a LilyGo T-Display TF shield

Arduino IDE 1.8.19 on an Ubuntu platform
Esp32 board support 2.0.17

I am able to either;
Have the onboard display working using TFT_eSPI.h
Or have the SD card working using SD_MMC.h
Naturally I want to use both.

If I try to have both components enabled I receive compile errors of the type
'File' does not name a type; did you mean 'pipe'
File myFile;
(Complete error messages log to follow below)

The trigger for the error from the working SD card code is to enable the line
#include <TFT_eSPI.h>
The other two libraries included for display support do not impact the compile.

Below are two copies of the same code;
SD-test1, in which the Display works and the SD card functionality has been commented out.
SD-test, in which the SD card works and the Display functionality has been commented out.

If I remove the comment from the #include <TFT_eSPI.h> I immediately get the compile error.

SD-test1.ino file (Working Display)

[code]
//======================================================================
//  Program: SD-test1
//  Test file operations to SD card
//  
//  This version has Display enabled and SD components commented out
//
//  Board type: LilyGo T-Display S3 AMOLED
//  Description:  A simple test of SD card functions.
//  MicroSD card supported via LilyGo T-Display TF Shield
//  https://www.lilygo.cc/products/t-display-tf-shied?srsltid=AfmBOorbrc3cyIZA4UGzFtaIu9-Ihddx29LG0Z1kAkzrwAMHf2vVXqrC
//
//  pins_config.h is the standard file from https://github.com/Xinyuan-LilyGO/T-Display-S3-AMOLED/blob/main/examples/factory/pins_config.h
//  along with the following to support SD card and attached GPS module
//  #define PIN_SD_CMD    13   - copied from standard T-Display example files
//  #define PIN_SD_CLK    11   - copied from standard T-Display example files
//  #define PIN_SD_D0     12   - copied from standard T-Display example files
//  #define GPS_RX 44          - not required for this sketch
//  #define GPS_TX 43          - not required for this sketch
//
//  Tested and working 20240906 with SD components commented out
//  Merely displays a splash screen during setup, stolen largly from Volos-Hello World
//======================================================================

//======================================================================
// Add constants
#include "pins_config.h"
#define DEBUG_PORT Serial
#define DEBUG_PORT_BAUD 115200

const uint32_t COMMAND_DELAY = 250;


//======================================================================
// Add element support and definitions


//----------------------------------------------------------------------
//Add Display support
#include "rm67162.h"
#include <TFT_eSPI.h>
#include <SPI.h>

TFT_eSPI tft = TFT_eSPI();
TFT_eSprite sprite = TFT_eSprite(&tft);

//----------------------------------------------------------------------
// Add support and definitions for SD card
//#include "FS.h"
//#include "SD_MMC.h"

// Additional requirements for recoding and file manipulation
int record = LOW;       // Flag to choose to 'record' to SD card if set HIGH
bool recording = false;
bool has_valid_position = false;
String recording_file = "";
// Used to construct new Directory name in recordOnOff()
String newYear;
String newMonth;
String newDay;
String newDir;  // New directory name

//File myFile;  // compiler fails here if I include TFT_eSPI.h

//======================================================================
//  Start setup code

void setup()
{
  Serial.begin(115200);
  //  while (!Serial)
  //    ;

  delay( COMMAND_DELAY );


  Serial.println  ("Display setup");
  Display_setup();               //setup display module, disabled due to compile error

  Serial.println  ("SD setup");

  //SD_setup();                        //setup SD card

  Serial.println  ("End of Setup: ");

  //  End of setup
}

//======================================================================
//  Setup sub-routine code segments
//  Disabled due to error when adding #include TFT_eSPI.h


  //****************************************************
  // Display module setup
  //****************************************************
  static void Display_setup() {
  // Initialize AMOLED LCD and set properties

  rm67162_init();  // amoled lcd initialization
  lcd_setRotation(1);
  sprite.createSprite(536, 240);
  sprite.setSwapBytes(1);

  sprite.fillSprite(TFT_BLACK);
  sprite.drawString("Hello World", 20, 20, 4);
  sprite.fillRect(10, 100, 60, 60, TFT_RED);
  sprite.fillRect(80, 100, 60, 60, TFT_GREEN);
  sprite.fillRect(150, 100, 60, 60, TFT_BLUE);
  sprite.drawString("102.45", 200, 100, 8);

  lcd_PushColors(0, 0, 536, 240, (uint16_t*)sprite.getPointer());

  }



/*
//****************************************************
// SD card setup
//****************************************************
void SD_setup() {
  SD_MMC.setPins(PIN_SD_CLK, PIN_SD_CMD, PIN_SD_D0);
  if (!SD_MMC.begin("/sdcard", true, true)) {
    Serial.println("Card Mount Failed");
    return;
  }
  uint8_t cardType = SD_MMC.cardType();

  if (cardType == CARD_NONE) {
    Serial.println("No SD_MMC card attached");
    return;
  }

  Serial.print("SD_MMC Card Type: ");
  if (cardType == CARD_MMC) {
    Serial.println("MMC");
  } else if (cardType == CARD_SD) {
    Serial.println("SDSC");
  } else if (cardType == CARD_SDHC) {
    Serial.println("SDHC");
  } else {
    Serial.println("UNKNOWN");
  }

  uint64_t cardSize = SD_MMC.cardSize() / (1024 * 1024);
  Serial.printf("SD_MMC Card Size: %lluMB\n", cardSize);


  listDir(SD_MMC, "/", 0);      //Display current card contents

  //
  //Create new flie and optionally directory for recording
  //
  newDir = "/NewDir1";            //Manually select directory for now

  //Does the directory already exist? If not create it.
  if (!SD_MMC.exists(newDir))
    (SD_MMC.mkdir(newDir));

  // Directory should now exist. Now set the new file to use
  recording_file = "LogFile" + getNextFileName(SD_MMC);           //Scan directory to build next file name
  //Open the file and add column headings
  File myFile = SD_MMC.open(newDir + "/" + recording_file, FILE_WRITE );
  if (myFile) {
    myFile.println("New file created");                           //Apply file header.
    myFile.flush();
    // close the file
    myFile.close();
    Serial.println ("File created");
  }


  //
  //Now append some data to the file
  //

  // Write 3 records of data to SD card
  //  File myFile =
  SD_MMC.open(newDir + "/" + recording_file, FILE_APPEND );
  if (myFile) {
    myFile.println("Record 1 added: ");
    myFile.flush();
    // close the file
    myFile.close();
  }

  SD_MMC.open(newDir + "/" + recording_file, FILE_APPEND );
  if (myFile) {
    myFile.println("Record 2 added: ");
    myFile.flush();
    // close the file
    myFile.close();
  }

  SD_MMC.open(newDir + "/" + recording_file, FILE_APPEND );
  if (myFile) {
    myFile.println("Record 3 added: ");
    myFile.flush();
    // close the file
    myFile.close();
    Serial.println ("File recording completed");
  }

  listDir(SD_MMC, "/", 0);         //Display current card contents
  listDir(SD_MMC, "/NewDir1", 0);

}
*/

//======================================================================
// MAIN LOOP
void loop()
{
  // Halt for debugging
}


//****************************************************
// Test stuff for SD functions
//****************************************************
/*
//----------------------------------------------------
//  Scan the directory and build the next file name.

String getNextFileName(fs::FS & fs) {
  int count = 1;
  File root = fs.open(newDir);
  if (!root) {
    Serial.println("Failed to open directory");
    return "";
  }
  if (!root.isDirectory()) {
    Serial.println("Not a directory");
    return "";
  }

  File file = root.openNextFile();
  while (file) {
    if (!file.isDirectory()) {
      count++;
    }
    file = root.openNextFile();
  }
  char buffer [9];
  sprintf (buffer, "%02d.csv", count);
  return buffer;

}

//----------------------------------------------------
//  List the specified directory.

void listDir(fs::FS &fs, const char *dirname, uint8_t levels)
{
  Serial.printf("Listing directory: %s\n", dirname);

  File root = fs.open(dirname);
  if (!root) {
    Serial.println("Failed to open directory");
    return;
  }
  if (!root.isDirectory()) {
    Serial.println("Not a directory");
    return;
  }

  File file = root.openNextFile();
  while (file) {
    if (file.isDirectory()) {
      Serial.print("  DIR : ");
      Serial.println(file.name());
      if (levels) {
        listDir(fs, file.path(), levels - 1);
      }
    } else {
      Serial.print("  FILE: ");
      Serial.print(file.name());
      Serial.print("  SIZE: ");
      Serial.println(file.size());
    }
    file = root.openNextFile();
  }
}
*/
[/code]

Below is SD-test.ino in its failing state. This can be made to compile if the TFT_eSPI.h is commented out.

[code]
//======================================================================
//  Program: SD-test
//  Test file operations to SD card
//  
//  This version has SD components enabled and Display commented out
//
//  Board type: LilyGo T-Display S3 AMOLED
//  Description:  A simple test of SD card functions.
//  MicroSD card supported via LilyGo T-Display TF Shield
//  https://www.lilygo.cc/products/t-display-tf-shied?srsltid=AfmBOorbrc3cyIZA4UGzFtaIu9-Ihddx29LG0Z1kAkzrwAMHf2vVXqrC
//
//  pins_config.h is the standard file from https://github.com/Xinyuan-LilyGO/T-Display-S3-AMOLED/blob/main/examples/factory/pins_config.h
//  along with the following to support SD card and attached GPS module
//  #define PIN_SD_CMD    13   - copied from standard T-Display example files
//  #define PIN_SD_CLK    11   - copied from standard T-Display example files
//  #define PIN_SD_D0     12   - copied from standard T-Display example files
//  #define GPS_RX 44          - not required for this sketch
//  #define GPS_TX 43          - not required for this sketch
//
//  Tested and working 20240906 with Display components commented out
//  Does some simple SD operations, display directories, creates a new log file and appends three lines
// 
//  Under the "Add Display Support section I can add
//  #include "rm67162.h"
//  #include <SPI.h>    and compile completes OK
//  If I add (either with or without the above two files)
//  #include <TFT_eSPI.h>
//  Compile fails with
//  SD-test:70:1: error: 'File' does not name a type; did you mean 'pipe'?
//  File myFile;  // compiler fails here if I include TFT_eSPI.h
//  ^~~~
//  pipe
//  
//======================================================================

//======================================================================
// Add constants
#include "pins_config.h"
#define DEBUG_PORT Serial
#define DEBUG_PORT_BAUD 115200

const uint32_t COMMAND_DELAY = 250;


//======================================================================
// Add element support and definitions


//----------------------------------------------------------------------
//Add Display support
#include "rm67162.h"
#include <TFT_eSPI.h>
#include <SPI.h>

//TFT_eSPI tft = TFT_eSPI();
//TFT_eSprite sprite = TFT_eSprite(&tft);

//----------------------------------------------------------------------
// Add support and definitions for SD card
#include "FS.h"
#include "SD_MMC.h"

// Additional requirements for recoding and file manipulation
int record = LOW;       // Flag to choose to 'record' to SD card if set HIGH
bool recording = false;
bool has_valid_position = false;
String recording_file = "";
// Used to construct new Directory name in recordOnOff()
String newYear;
String newMonth;
String newDay;
String newDir;  // New directory name

File myFile;  // compiler fails here if I include TFT_eSPI.h

//======================================================================
//  Start setup code

void setup()
{
  Serial.begin(115200);
  //  while (!Serial)
  //    ;

  delay( COMMAND_DELAY );


  Serial.println  ("Display setup");
  //Display_setup();               //setup display module, disabled due to compile error

  Serial.println  ("SD setup");

  SD_setup();                        //setup SD card

  Serial.println  ("End of Setup: ");

  //  End of setup
}

//======================================================================
//  Setup sub-routine code segments
//  Disabled due to error when adding #include TFT_eSPI.h

/*
  //****************************************************
  // Display module setup
  //****************************************************
  static void Display_setup() {
  // Initialize AMOLED LCD and set properties

  rm67162_init();  // amoled lcd initialization
  lcd_setRotation(1);
  sprite.createSprite(536, 240);
  sprite.setSwapBytes(1);

  sprite.fillSprite(TFT_BLACK);
  sprite.drawString("Hello World", 20, 20, 4);
  sprite.fillRect(10, 100, 60, 60, TFT_RED);
  sprite.fillRect(80, 100, 60, 60, TFT_GREEN);
  sprite.fillRect(150, 100, 60, 60, TFT_BLUE);
  sprite.drawString("102.45", 200, 100, 8);

  lcd_PushColors(0, 0, 536, 240, (uint16_t*)sprite.getPointer());

  }

*/


//****************************************************
// SD card setup
//****************************************************
void SD_setup() {
  SD_MMC.setPins(PIN_SD_CLK, PIN_SD_CMD, PIN_SD_D0);
  if (!SD_MMC.begin("/sdcard", true, true)) {
    Serial.println("Card Mount Failed");
    return;
  }
  uint8_t cardType = SD_MMC.cardType();

  if (cardType == CARD_NONE) {
    Serial.println("No SD_MMC card attached");
    return;
  }

  Serial.print("SD_MMC Card Type: ");
  if (cardType == CARD_MMC) {
    Serial.println("MMC");
  } else if (cardType == CARD_SD) {
    Serial.println("SDSC");
  } else if (cardType == CARD_SDHC) {
    Serial.println("SDHC");
  } else {
    Serial.println("UNKNOWN");
  }

  uint64_t cardSize = SD_MMC.cardSize() / (1024 * 1024);
  Serial.printf("SD_MMC Card Size: %lluMB\n", cardSize);


  listDir(SD_MMC, "/", 0);      //Display current card contents

  //
  //Create new flie and optionally directory for recording
  //
  newDir = "/NewDir1";            //Manually select directory for now

  //Does the directory already exist? If not create it.
  if (!SD_MMC.exists(newDir))
    (SD_MMC.mkdir(newDir));

  // Directory should now exist. Now set the new file to use
  recording_file = "LogFile" + getNextFileName(SD_MMC);           //Scan directory to build next file name
  //Open the file and add column headings
  File myFile = SD_MMC.open(newDir + "/" + recording_file, FILE_WRITE );
  if (myFile) {
    myFile.println("New file created");                           //Apply file header.
    myFile.flush();
    // close the file
    myFile.close();
    Serial.println ("File created");
  }


  //
  //Now append some data to the file
  //

  // Write 3 records of data to SD card
  //  File myFile =
  SD_MMC.open(newDir + "/" + recording_file, FILE_APPEND );
  if (myFile) {
    myFile.println("Record 1 added: ");
    myFile.flush();
    // close the file
    myFile.close();
  }

  SD_MMC.open(newDir + "/" + recording_file, FILE_APPEND );
  if (myFile) {
    myFile.println("Record 2 added: ");
    myFile.flush();
    // close the file
    myFile.close();
  }

  SD_MMC.open(newDir + "/" + recording_file, FILE_APPEND );
  if (myFile) {
    myFile.println("Record 3 added: ");
    myFile.flush();
    // close the file
    myFile.close();
    Serial.println ("File recording completed");
  }

  listDir(SD_MMC, "/", 0);         //Display current card contents
  listDir(SD_MMC, "/NewDir1", 0);

}


//======================================================================
// MAIN LOOP
void loop()
{
  // Halt for debugging
}


//****************************************************
// Test stuff for SD functions
//****************************************************

//----------------------------------------------------
//  Scan the directory and build the next file name.

String getNextFileName(fs::FS & fs) {
  int count = 1;
  File root = fs.open(newDir);
  if (!root) {
    Serial.println("Failed to open directory");
    return "";
  }
  if (!root.isDirectory()) {
    Serial.println("Not a directory");
    return "";
  }

  File file = root.openNextFile();
  while (file) {
    if (!file.isDirectory()) {
      count++;
    }
    file = root.openNextFile();
  }
  char buffer [9];
  sprintf (buffer, "%02d.csv", count);
  return buffer;

}

//----------------------------------------------------
//  List the specified directory.

void listDir(fs::FS &fs, const char *dirname, uint8_t levels)
{
  Serial.printf("Listing directory: %s\n", dirname);

  File root = fs.open(dirname);
  if (!root) {
    Serial.println("Failed to open directory");
    return;
  }
  if (!root.isDirectory()) {
    Serial.println("Not a directory");
    return;
  }

  File file = root.openNextFile();
  while (file) {
    if (file.isDirectory()) {
      Serial.print("  DIR : ");
      Serial.println(file.name());
      if (levels) {
        listDir(fs, file.path(), levels - 1);
      }
    } else {
      Serial.print("  FILE: ");
      Serial.print(file.name());
      Serial.print("  SIZE: ");
      Serial.println(file.size());
    }
    file = root.openNextFile();
  }
}

[/code]

Below is pins_config.h just in case this is of interest

[code]
#pragma once

/***********************config*************************/
#define LCD_USB_QSPI_DREVER   1

#define SPI_FREQUENCY         75000000
#define TFT_SPI_MODE          SPI_MODE0
#define TFT_SPI_HOST          SPI2_HOST

#define EXAMPLE_LCD_H_RES     536
#define EXAMPLE_LCD_V_RES     240
#define LVGL_LCD_BUF_SIZE     (EXAMPLE_LCD_H_RES * EXAMPLE_LCD_V_RES)

// #define WIFI_SSID             "YOUR-SSID"
// #define WIFI_PASSWORD         "YOUR-PSW"
#define WIFI_SSID             "xinyuandianzi"
#define WIFI_PASSWORD         "AA15994823428"

#define WIFI_CONNECT_WAIT_MAX (30 * 1000)

#define NTP_SERVER1           "pool.ntp.org"
#define NTP_SERVER2           "time.nist.gov"
#define GMT_OFFSET_SEC        0
#define DAY_LIGHT_OFFSET_SEC  0

/* Automatically update local time */
#define GET_TIMEZONE_API      "https://ipapi.co/timezone/"

/***********************config*************************/

#define TFT_WIDTH             240
#define TFT_HEIGHT            536
#define SEND_BUF_SIZE         (0x4000) //(LCD_WIDTH * LCD_HEIGHT + 8) / 10

#define TFT_TE                9
#define TFT_SDO               8

#define TFT_DC                7
#define TFT_RES               17
#define TFT_CS                6
#define TFT_MOSI              18
#define TFT_SCK               47

#define TFT_QSPI_CS           6
#define TFT_QSPI_SCK          47
#define TFT_QSPI_D0           18
#define TFT_QSPI_D1           7
#define TFT_QSPI_D2           48
#define TFT_QSPI_D3           5
#define TFT_QSPI_RST          17

#define PIN_LED               38
#define PIN_BAT_VOLT          4

#define PIN_BUTTON_1          0
#define PIN_BUTTON_2          21

/* External expansion  added from Non AMOLED examples*/
#define PIN_SD_CMD    13
#define PIN_SD_CLK    11
#define PIN_SD_D0     12

#define GPS_RX 44
#define GPS_TX 43
[/code]

The compile errors that I receive are:

Arduino: 1.8.19 (Linux), Board: "ESP32S3 Dev Module, Disabled, OPI PSRAM, QIO 80MHz, 16MB (128Mb), Core 1, Core 1, Hardware CDC and JTAG, Enabled, Disabled, Disabled, UART0 / Hardware CDC, 16M Flash (3MB APP/9.9MB FATFS), 240MHz (WiFi), 921600, None, Disabled"











SD-test:74:1: error: 'File' does not name a type; did you mean 'pipe'?
 File myFile;  // compiler fails here if I include TFT_eSPI.h
 ^~~~
 pipe
/home/alan/Arduino/Projects/Current load/T-display1/SD-test/SD-test.ino: In function 'void SD_setup()':
SD-test:175:3: error: 'File' was not declared in this scope
   File myFile = SD_MMC.open(newDir + "/" + recording_file, FILE_WRITE );
   ^~~~
/home/alan/Arduino/Projects/Current load/T-display1/SD-test/SD-test.ino:175:3: note: suggested alternative:
In file included from /home/alan/Arduino/libraries/TFT_eSPI/Processors/TFT_eSPI_ESP32_S3.h:152,
                 from /home/alan/Arduino/libraries/TFT_eSPI/TFT_eSPI.h:96,
                 from /home/alan/Arduino/Projects/Current load/T-display1/SD-test/SD-test.ino:52:
/home/alan/.arduino15/packages/esp32/hardware/esp32/2.0.17/libraries/FS/src/FS.h:47:7: note:   'fs::File'
 class File : public Stream
       ^~~~
SD-test:176:7: error: 'myFile' was not declared in this scope
   if (myFile) {
       ^~~~~~
/home/alan/Arduino/Projects/Current load/T-display1/SD-test/SD-test.ino:176:7: note: suggested alternative: 'mktime'
   if (myFile) {
       ^~~~~~
       mktime
SD-test:192:7: error: 'myFile' was not declared in this scope
   if (myFile) {
       ^~~~~~
/home/alan/Arduino/Projects/Current load/T-display1/SD-test/SD-test.ino:192:7: note: suggested alternative: 'mktime'
   if (myFile) {
       ^~~~~~
       mktime
SD-test:200:7: error: 'myFile' was not declared in this scope
   if (myFile) {
       ^~~~~~
/home/alan/Arduino/Projects/Current load/T-display1/SD-test/SD-test.ino:200:7: note: suggested alternative: 'mktime'
   if (myFile) {
       ^~~~~~
       mktime
SD-test:208:7: error: 'myFile' was not declared in this scope
   if (myFile) {
       ^~~~~~
/home/alan/Arduino/Projects/Current load/T-display1/SD-test/SD-test.ino:208:7: note: suggested alternative: 'mktime'
   if (myFile) {
       ^~~~~~
       mktime
/home/alan/Arduino/Projects/Current load/T-display1/SD-test/SD-test.ino: In function 'String getNextFileName(fs::FS&)':
SD-test:239:3: error: 'File' was not declared in this scope
   File root = fs.open(newDir);
   ^~~~
/home/alan/Arduino/Projects/Current load/T-display1/SD-test/SD-test.ino:239:3: note: suggested alternative:
In file included from /home/alan/Arduino/libraries/TFT_eSPI/Processors/TFT_eSPI_ESP32_S3.h:152,
                 from /home/alan/Arduino/libraries/TFT_eSPI/TFT_eSPI.h:96,
                 from /home/alan/Arduino/Projects/Current load/T-display1/SD-test/SD-test.ino:52:
/home/alan/.arduino15/packages/esp32/hardware/esp32/2.0.17/libraries/FS/src/FS.h:47:7: note:   'fs::File'
 class File : public Stream
       ^~~~
SD-test:240:8: error: 'root' was not declared in this scope
   if (!root) {
        ^~~~
/home/alan/Arduino/Projects/Current load/T-display1/SD-test/SD-test.ino:240:8: note: suggested alternative: 'font'
   if (!root) {
        ^~~~
        font
SD-test:244:8: error: 'root' was not declared in this scope
   if (!root.isDirectory()) {
        ^~~~
/home/alan/Arduino/Projects/Current load/T-display1/SD-test/SD-test.ino:244:8: note: suggested alternative: 'font'
   if (!root.isDirectory()) {
        ^~~~
        font
SD-test:249:7: error: expected ';' before 'file'
   File file = root.openNextFile();
       ^~~~~
       ;
SD-test:250:10: error: 'file' was not declared in this scope
   while (file) {
          ^~~~
/home/alan/Arduino/Projects/Current load/T-display1/SD-test/SD-test.ino:250:10: note: suggested alternative: 'pipe'
   while (file) {
          ^~~~
          pipe
SD-test:254:12: error: 'root' was not declared in this scope
     file = root.openNextFile();
            ^~~~
/home/alan/Arduino/Projects/Current load/T-display1/SD-test/SD-test.ino:254:12: note: suggested alternative: 'font'
     file = root.openNextFile();
            ^~~~
            font
/home/alan/Arduino/Projects/Current load/T-display1/SD-test/SD-test.ino: In function 'void listDir(fs::FS&, const char*, uint8_t)':
SD-test:269:3: error: 'File' was not declared in this scope
   File root = fs.open(dirname);
   ^~~~
/home/alan/Arduino/Projects/Current load/T-display1/SD-test/SD-test.ino:269:3: note: suggested alternative:
In file included from /home/alan/Arduino/libraries/TFT_eSPI/Processors/TFT_eSPI_ESP32_S3.h:152,
                 from /home/alan/Arduino/libraries/TFT_eSPI/TFT_eSPI.h:96,
                 from /home/alan/Arduino/Projects/Current load/T-display1/SD-test/SD-test.ino:52:
/home/alan/.arduino15/packages/esp32/hardware/esp32/2.0.17/libraries/FS/src/FS.h:47:7: note:   'fs::File'
 class File : public Stream
       ^~~~
SD-test:270:8: error: 'root' was not declared in this scope
   if (!root) {
        ^~~~
/home/alan/Arduino/Projects/Current load/T-display1/SD-test/SD-test.ino:270:8: note: suggested alternative: 'font'
   if (!root) {
        ^~~~
        font
SD-test:274:8: error: 'root' was not declared in this scope
   if (!root.isDirectory()) {
        ^~~~
/home/alan/Arduino/Projects/Current load/T-display1/SD-test/SD-test.ino:274:8: note: suggested alternative: 'font'
   if (!root.isDirectory()) {
        ^~~~
        font
SD-test:279:7: error: expected ';' before 'file'
   File file = root.openNextFile();
       ^~~~~
       ;
SD-test:280:10: error: 'file' was not declared in this scope
   while (file) {
          ^~~~
/home/alan/Arduino/Projects/Current load/T-display1/SD-test/SD-test.ino:280:10: note: suggested alternative: 'pipe'
   while (file) {
          ^~~~
          pipe
SD-test:293:12: error: 'root' was not declared in this scope
     file = root.openNextFile();
            ^~~~
/home/alan/Arduino/Projects/Current load/T-display1/SD-test/SD-test.ino:293:12: note: suggested alternative: 'font'
     file = root.openNextFile();
            ^~~~
            font
exit status 1
'File' does not name a type; did you mean 'pipe'?


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

I suspectted some sort of clash with the term File in the TFT library, but my novice abilities could not find any possible cause.

Appologies if I am in the wrong place or haven't provided enough information, and thankyou in advance for your support.

if the SD card is sharing a SPI bus with other devices there can be problems, see Sharing the SPI bus among SD card and other SPI devices

if you run separate test programs (generally each library comes with example test code) with nothing else connected do the SD card and other devices work OK

Horace, thanks for the reply.
The SD card is not using the SPI bus, but is instead accessed in SD mode.
This uses only 3 pins, Clock (CLK), Command (CMD), Data (Dat0). There are implementations with up to 4 data bits, but this Shield only uses 1 data bit.
The pins are identified in the pins_config.h file above.
The screen uses a QSPI and again the pins are identified in the above file.

Yes, everything works when independently configured.
The issue is that the SD-test1 above fails to compile as soon as I include the TFT library.

My initial testing of the SD card was using the LilyGo T-Display S3 example SD.ino which worked as expected.
This also fails however if I just include the TFT library.

Another day of messing about and I have made it work but I do not understand why.
Any help understanding why this solution worked would be appreciated.

I found that if I moved the #includes for the SD card to before the ones for the Display then the sketch compiles OK.

Is this really a thing where the order of this stuff matters?
If so how do you know what should be placed first.

Below is the code which now compiles.
Apart from the order of the lines in the section "Add element support and definitions" and the un-commenting to fully enable both the SD and the display, there is no difference to the code I posted earlier

[code]
//======================================================================
//  Program: SD-test
//  Test file operations to SD card
//  
//  This version has SD components enabled and Display commented out
//
//  Board type: LilyGo T-Display S3 AMOLED
//  Description:  A simple test of SD card functions.
//  MicroSD card supported via LilyGo T-Display TF Shield
//  https://www.lilygo.cc/products/t-display-tf-shied?srsltid=AfmBOorbrc3cyIZA4UGzFtaIu9-Ihddx29LG0Z1kAkzrwAMHf2vVXqrC
//
//  pins_config.h is the standard file from https://github.com/Xinyuan-LilyGO/T-Display-S3-AMOLED/blob/main/examples/factory/pins_config.h
//  along with the following to support SD card and attached GPS module
//  #define PIN_SD_CMD    13   - copied from standard T-Display example files
//  #define PIN_SD_CLK    11   - copied from standard T-Display example files
//  #define PIN_SD_D0     12   - copied from standard T-Display example files
//  #define GPS_RX 44          - not required for this sketch
//  #define GPS_TX 43          - not required for this sketch
//
//  Tested and working 20240906 with Display components commented out
//  Does some simple SD operations, display directories, creates a new log file and appends three lines
// 
//  Under the "Add Display Support section I can add
//  #include "rm67162.h"
//  #include <SPI.h>    and compile completes OK
//  If I add (either with or without the above two files)
//  #include <TFT_eSPI.h>
//  Compile fails with
//  SD-test:70:1: error: 'File' does not name a type; did you mean 'pipe'?
//  File myFile;  // compiler fails here if I include TFT_eSPI.h
//  ^~~~
//  pipe
//  
//======================================================================

//======================================================================
// Add constants
#include "pins_config.h"
#define DEBUG_PORT Serial
#define DEBUG_PORT_BAUD 115200

const uint32_t COMMAND_DELAY = 250;


//======================================================================
// Add element support and definitions

//----------------------------------------------------------------------
// Add support and definitions for SD card
#include "FS.h"
#include "SD_MMC.h"

// Additional requirements for recoding and file manipulation
int record = LOW;       // Flag to choose to 'record' to SD card if set HIGH
bool recording = false;
bool has_valid_position = false;
String recording_file = "";
// Used to construct new Directory name in recordOnOff()
String newYear;
String newMonth;
String newDay;
String newDir;  // New directory name


//----------------------------------------------------------------------
//Add Display support
#include "rm67162.h"
#include <TFT_eSPI.h>
#include <SPI.h>

TFT_eSPI tft = TFT_eSPI();
TFT_eSprite sprite = TFT_eSprite(&tft);


File myFile;  // compiler fails here if I include TFT_eSPI.h

//======================================================================
//  Start setup code

void setup()
{
  Serial.begin(115200);
  //  while (!Serial)
  //    ;

  delay( COMMAND_DELAY );


  Serial.println  ("Display setup");
  //Display_setup();               //setup display module, disabled due to compile error

  Serial.println  ("SD setup");

  SD_setup();                        //setup SD card

  Serial.println  ("End of Setup: ");

  //  End of setup
}

//======================================================================
//  Setup sub-routine code segments
//  Disabled due to error when adding #include TFT_eSPI.h


  //****************************************************
  // Display module setup
  //****************************************************
  static void Display_setup() {
  // Initialize AMOLED LCD and set properties

  rm67162_init();  // amoled lcd initialization
  lcd_setRotation(1);
  sprite.createSprite(536, 240);
  sprite.setSwapBytes(1);

  sprite.fillSprite(TFT_BLACK);
  sprite.drawString("Hello World", 20, 20, 4);
  sprite.fillRect(10, 100, 60, 60, TFT_RED);
  sprite.fillRect(80, 100, 60, 60, TFT_GREEN);
  sprite.fillRect(150, 100, 60, 60, TFT_BLUE);
  sprite.drawString("102.45", 200, 100, 8);

  lcd_PushColors(0, 0, 536, 240, (uint16_t*)sprite.getPointer());

  }




//****************************************************
// SD card setup
//****************************************************
void SD_setup() {
  SD_MMC.setPins(PIN_SD_CLK, PIN_SD_CMD, PIN_SD_D0);
  if (!SD_MMC.begin("/sdcard", true, true)) {
    Serial.println("Card Mount Failed");
    return;
  }
  uint8_t cardType = SD_MMC.cardType();

  if (cardType == CARD_NONE) {
    Serial.println("No SD_MMC card attached");
    return;
  }

  Serial.print("SD_MMC Card Type: ");
  if (cardType == CARD_MMC) {
    Serial.println("MMC");
  } else if (cardType == CARD_SD) {
    Serial.println("SDSC");
  } else if (cardType == CARD_SDHC) {
    Serial.println("SDHC");
  } else {
    Serial.println("UNKNOWN");
  }

  uint64_t cardSize = SD_MMC.cardSize() / (1024 * 1024);
  Serial.printf("SD_MMC Card Size: %lluMB\n", cardSize);


  listDir(SD_MMC, "/", 0);      //Display current card contents

  //
  //Create new flie and optionally directory for recording
  //
  newDir = "/NewDir1";            //Manually select directory for now

  //Does the directory already exist? If not create it.
  if (!SD_MMC.exists(newDir))
    (SD_MMC.mkdir(newDir));

  // Directory should now exist. Now set the new file to use
  recording_file = "LogFile" + getNextFileName(SD_MMC);           //Scan directory to build next file name
  //Open the file and add column headings
  File myFile = SD_MMC.open(newDir + "/" + recording_file, FILE_WRITE );
  if (myFile) {
    myFile.println("New file created");                           //Apply file header.
    myFile.flush();
    // close the file
    myFile.close();
    Serial.println ("File created");
  }


  //
  //Now append some data to the file
  //

  // Write 3 records of data to SD card
  //  File myFile =
  SD_MMC.open(newDir + "/" + recording_file, FILE_APPEND );
  if (myFile) {
    myFile.println("Record 1 added: ");
    myFile.flush();
    // close the file
    myFile.close();
  }

  SD_MMC.open(newDir + "/" + recording_file, FILE_APPEND );
  if (myFile) {
    myFile.println("Record 2 added: ");
    myFile.flush();
    // close the file
    myFile.close();
  }

  SD_MMC.open(newDir + "/" + recording_file, FILE_APPEND );
  if (myFile) {
    myFile.println("Record 3 added: ");
    myFile.flush();
    // close the file
    myFile.close();
    Serial.println ("File recording completed");
  }

  listDir(SD_MMC, "/", 0);         //Display current card contents
  listDir(SD_MMC, "/NewDir1", 0);

}


//======================================================================
// MAIN LOOP
void loop()
{
  // Halt for debugging
}


//****************************************************
// Test stuff for SD functions
//****************************************************

//----------------------------------------------------
//  Scan the directory and build the next file name.

String getNextFileName(fs::FS & fs) {
  int count = 1;
  File root = fs.open(newDir);
  if (!root) {
    Serial.println("Failed to open directory");
    return "";
  }
  if (!root.isDirectory()) {
    Serial.println("Not a directory");
    return "";
  }

  File file = root.openNextFile();
  while (file) {
    if (!file.isDirectory()) {
      count++;
    }
    file = root.openNextFile();
  }
  char buffer [9];
  sprintf (buffer, "%02d.csv", count);
  return buffer;

}

//----------------------------------------------------
//  List the specified directory.

void listDir(fs::FS &fs, const char *dirname, uint8_t levels)
{
  Serial.printf("Listing directory: %s\n", dirname);

  File root = fs.open(dirname);
  if (!root) {
    Serial.println("Failed to open directory");
    return;
  }
  if (!root.isDirectory()) {
    Serial.println("Not a directory");
    return;
  }

  File file = root.openNextFile();
  while (file) {
    if (file.isDirectory()) {
      Serial.print("  DIR : ");
      Serial.println(file.name());
      if (levels) {
        listDir(fs, file.path(), levels - 1);
      }
    } else {
      Serial.print("  FILE: ");
      Serial.print(file.name());
      Serial.print("  SIZE: ");
      Serial.println(file.size());
    }
    file = root.openNextFile();
  }
}
[/code]