Error: undefined reference to `vtable for AudioOutputULP"

Trying to compile my project and I keep getting this error.

I’ve deleted and updated/replaced all the packages in \.platformio\packages.

I made sure the referenced file in the error is in \PlatformIO\Projects\ESP32MP3BasicPlayer\.pio\libdeps\esp32dev\ESP8266Audio\src.

Any help would be really apprecaited! Thanks!

ERROR

Linking .pio\build\esp32dev\firmware.elf
c:/users/echo/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\esp32dev\src\main.cpp.o:(.literal._Z5setupv+0x1c): undefined reference to `vtable for AudioOutputULP'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\esp32dev\firmware.elf] Error 1

Code

#include <Arduino.h>
#include "AudioFileSourceSD.h"
#include "AudioOutputULP.h"
#include "AudioGeneratorWAV.h"

#define SD_CardSelect 4      // Define the SD card select pin

//  SPI / SD Card Pins
// #define SCK 18  // GPIO 18
// #define MISO 19 // GPIO 19
// #define MOSI 23 // GPIO 23

// Audio out is pin GPIO 25

File dir;
AudioFileSourceSD *source = NULL;
AudioOutputULP *output = NULL;
AudioGeneratorWAV *decoder = NULL;
bool allFilesPlayed = false;

void setup() {
  Serial.begin(115200);
  Serial.println();
  delay(1000);

  audioLogger = &Serial;
  source = new AudioFileSourceSD();
  output = new AudioOutputULP(1);  // ()=stereo (1)=mono
  decoder = new AudioGeneratorWAV();

  Serial.println("Initializing SD card...");
  if (SD.begin(SD_CardSelect)) { // Use the defined SD_CardSelect pin
    Serial.println("SD card initialization successful");
  } else {
    Serial.println("SD card initialization failed");
  }

  dir = SD.open("/");
  
  // Set the gain to 0.5 (50% volume)
  output->SetGain(0.5);
}

void loop() {
  if (!allFilesPlayed) {
    if ((decoder) && (decoder->isRunning())) {
      if (!decoder->loop()) {
        decoder->stop();
        Serial.println("Playback finished");
      }
    } else {
      File file = dir.openNextFile();
      if (file) {
        if (String(file.name()).endsWith(".wav")) {
          source->close();
          String filePath = "/" + String(file.name()); // Add "/" in front of the file name
          if (source->open(filePath.c_str())) {
            Serial.printf("Playing '%s' from SD card...\n", filePath.c_str());
            decoder->begin(source, output);
          } else {
            Serial.printf("Error opening '%s'\n", filePath.c_str());
          }
        }
      } else {
        Serial.println("All files played. Replaying...");
        dir.rewindDirectory(); // Reset the directory to replay files
        allFilesPlayed = true;
      }
    }
  } else {
    // You can add your replay logic here.
    // For example, you can reset 'allFilesPlayed' to false to replay indefinitely,
    // or implement a different replay strategy.
    dir.rewindDirectory();  // Reset the directory to replay files
    allFilesPlayed = false; // Reset the flag
  }
}

There seems to be a problem on Arduino-ESP32 where the source code for AudioOutputULP is not compiled (or rather, deactivated) if a ESP-IDF specific macro isn’t found:

The sketch seems to compile fine if you manually activate this macro. Not sure whether it will work during runtime or not.

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
  earlephilhower/ESP8266Audio@^1.9.9
build_flags = -DCONFIG_IDF_TARGET_ESP32

Linking .pio\build\esp32dev\firmware.elf
Retrieving maximum program size .pio\build\esp32dev\firmware.elf
Checking size .pio\build\esp32dev\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]   6.7% (used 22096 bytes from 327680 bytes)
Flash: [===       ]  26.0% (used 341077 bytes from 1310720 bytes)
Building .pio\build\esp32dev\firmware.bin
esptool.py v4.5.1
Creating esp32 image...
Merged 2 ELF sections
Successfully created esp32 image.
======================= [SUCCESS] Took 48.80 seconds =======================