Assistance fixing "'log_printf' was not declared in this scope" in compilation

Hello, I’m trying to compile a project for my ESP32 board. When I set the framework in platformio.ini to espidf the project compiles with no problem. When I change the framework to arduino then I receive the compile errors below. I’m looking for some guidance on how to determine where the problem is. It’s almost as if the wemos_d1_mini32 board doesn’t support Arduino but I don’t think that is the case.

Here is the compiler output

> Executing task: platformio run <

Processing wemos_d1_mini32 (platform: espressif32; board: wemos_d1_mini32; framework: arduino)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/wemos_d1_mini32.html
PLATFORM: Espressif 32 (3.2.0) > WeMos D1 MINI ESP32
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: 
 - framework-arduinoespressif32 3.10006.210326 (1.0.6) 
 - tool-esptoolpy 1.30000.201119 (3.0.0) 
 - toolchain-xtensa32 2.50200.97 (5.2.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 34 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pio/build/wemos_d1_mini32/src/main.cpp.o
Generating partitions .pio/build/wemos_d1_mini32/partitions.bin
Archiving .pio/build/wemos_d1_mini32/libFrameworkArduinoVariant.a
Indexing .pio/build/wemos_d1_mini32/libFrameworkArduinoVariant.a
Compiling .pio/build/wemos_d1_mini32/FrameworkArduino/Esp.cpp.o
Compiling .pio/build/wemos_d1_mini32/FrameworkArduino/FunctionalInterrupt.cpp.o
Compiling .pio/build/wemos_d1_mini32/FrameworkArduino/HardwareSerial.cpp.o
In file included from /home/jlehman/.platformio/packages/framework-arduinoespressif32/cores/esp32/esp32-hal.h:50:0,
                 from /home/jlehman/.platformio/packages/framework-arduinoespressif32/cores/esp32/HardwareSerial.h:51,
                 from /home/jlehman/.platformio/packages/framework-arduinoespressif32/cores/esp32/HardwareSerial.cpp:7:
/home/jlehman/.platformio/packages/framework-arduinoespressif32/cores/esp32/HardwareSerial.cpp: In member function 'void HardwareSerial::begin(long unsigned int, uint32_t, int8_t, int8_t, bool, long unsigned int)':
/home/jlehman/.platformio/packages/framework-arduinoespressif32/cores/esp32/esp32-hal-log.h:139:83: error: 'log_printf' was not declared in this scope
 #define log_e(format, ...) log_printf(ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__)
                                                                                   ^
/home/jlehman/.platformio/packages/framework-arduinoespressif32/cores/esp32/HardwareSerial.cpp:36:9: note: in expansion of macro 'log_e'
         log_e("Serial number is invalid, please use 0, 1 or 2");
         ^
/home/jlehman/.platformio/packages/framework-arduinoespressif32/cores/esp32/esp32-hal-log.h:139:83: error: 'log_printf' was not declared in this scope
 #define log_e(format, ...) log_printf(ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__)
                                                                                   ^
/home/jlehman/.platformio/packages/framework-arduinoespressif32/cores/esp32/HardwareSerial.cpp:73:13: note: in expansion of macro 'log_e'
             log_e("Could not detect baudrate. Serial data at the port must be present within the timeout for detection to be possible");
             ^
*** [.pio/build/wemos_d1_mini32/FrameworkArduino/HardwareSerial.cpp.o] Error 1
In file included from /home/jlehman/.platformio/packages/framework-arduinoespressif32/cores/esp32/esp32-hal.h:50:0,
                 from /home/jlehman/.platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:35,
                 from /home/jlehman/.platformio/packages/framework-arduinoespressif32/cores/esp32/Esp.cpp:20:
/home/jlehman/.platformio/packages/framework-arduinoespressif32/cores/esp32/Esp.cpp: In member function 'String EspClass::getSketchMD5()':
/home/jlehman/.platformio/packages/framework-arduinoespressif32/cores/esp32/esp32-hal-log.h:139:83: error: 'log_printf' was not declared in this scope
 #define log_e(format, ...) log_printf(ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__)
                                                                                   ^
/home/jlehman/.platformio/packages/framework-arduinoespressif32/cores/esp32/Esp.cpp:175:9: note: in expansion of macro 'log_e'
         log_e("Partition could not be found");
         ^
/home/jlehman/.platformio/packages/framework-arduinoespressif32/cores/esp32/esp32-hal-log.h:139:83: error: 'log_printf' was not declared in this scope
 #define log_e(format, ...) log_printf(ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__)
                                                                                   ^
/home/jlehman/.platformio/packages/framework-arduinoespressif32/cores/esp32/Esp.cpp:183:9: note: in expansion of macro 'log_e'
         log_e("Not enough memory to allocate buffer");
         ^
/home/jlehman/.platformio/packages/framework-arduinoespressif32/cores/esp32/esp32-hal-log.h:139:83: error: 'log_printf' was not declared in this scope
 #define log_e(format, ...) log_printf(ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__)
                                                                                   ^
/home/jlehman/.platformio/packages/framework-arduinoespressif32/cores/esp32/Esp.cpp:192:13: note: in expansion of macro 'log_e'
             log_e("Could not read buffer from flash");
             ^
*** [.pio/build/wemos_d1_mini32/FrameworkArduino/Esp.cpp.o] Error 1
====================================================================== [FAILED] Took 1.65 seconds ======================================================================
The terminal process "platformio 'run'" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.

Here is my main.cpp just in case there is something there that is the cause of my issue.

// ESP32
//#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include "driver/gpio.h"
//#include "freertos/FreeRTOS.h"
//#include "freertos/task.h"
#include "esp_log.h"
#include <Arduino.h>

#define MY_TAG "MAIN"

extern "C" {
  void app_main() {
    //ESP_LOGI(MY_TAG,"Starting...");
    //esp_log_level_set(MY_TAG, ESP_LOG_VERBOSE);

    while(true) {
      vTaskDelay(1000/portTICK_PERIOD_MS);
    }

  }
}

Thanks!

o_O Are you sure that when you compile with the Arduino framework, that you want to override app_main? In Arduino, applications should implement setup() and loop().

In any case, your problem is not reproducable for me. Using your ode with commented out calls to ESP_LOGI and esp_log_level_set gives

> Executing task in folder lib_path_repro: C:\Users\Max\AppData\Local\Programs\Python\Python38\Scripts\platformio.exe run --environment esp32dev <

Processing esp32dev (platform: espressif32; board: esp32dev; framework: arduino)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 (3.1.0) > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
 - framework-arduinoespressif32 3.10005.210308 (1.0.5)
 - tool-esptoolpy 1.30000.201119 (3.0.0)
 - toolchain-xtensa32 2.50200.97 (5.2.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 30 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pio\build\esp32dev\src\main.cpp.o
[..]
Indexing .pio\build\esp32dev\libFrameworkArduino.a
Linking .pio\build\esp32dev\firmware.elf
Retrieving maximum program size .pio\build\esp32dev\firmware.elf
Building .pio\build\esp32dev\firmware.bin
Checking size .pio\build\esp32dev\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   3.9% (used 12936 bytes from 327680 bytes)
Flash: [=         ]  13.6% (used 178508 bytes from 1310720 bytes)
esptool.py v3.0
============================= [SUCCESS] Took 8.30 seconds =============================

So I’d just recomment to update everything. In a CLI do

pio upgrade dev
pio platform update espressif32

and retry.

jlehman@asterix:~/Documents/PlatformIO/Projects/ESP32LoRaArduinoTest$ pio upgrade --dev
Please wait while upgrading PlatformIO ...
PlatformIO has been successfully upgraded to 5.2.0a5
Release notes: https://docs.platformio.org/en/latest/history.html



jlehman@asterix:~/Documents/PlatformIO/Projects/ESP32LoRaArduinoTest$ pio platform update espressif32
Platform espressif32
--------
Updating platformio/espressif32               3.2.0                              [Up-to-date]
Updating platformio/toolchain-xtensa32        2.50200.97 @ ~2.50200.0            [Up-to-date]
Updating platformio/toolchain-esp32ulp        1.22851.191205 @ ~1.22851.0        [Up-to-date]
Updating platformio/framework-arduinoespressif32 3.10006.210326 @ ~3.10006.0        [Up-to-date]
Updating platformio/framework-espidf          3.40200.210118 @ ~3.40200.0        [Up-to-date]
Updating platformio/tool-esptoolpy            1.30000.201119 @ ~1.30000.0        [Up-to-date]
Updating platformio/tool-openocd-esp32        2.1000.20201202 @ ~2.1000.0        [Up-to-date]
Updating platformio/tool-mkspiffs             2.230.0 @ ~2.230.0                 [Up-to-date]
Updating platformio/tool-cmake                3.16.4 @ ~3.16.0                   [Up-to-date]
Updating platformio/tool-ninja                1.7.1 @ ^1.7.0                     [Up-to-date]

Still having the issue. I think I will try completely uninstalling and reinstalling the program.

Thanks for your help!

Uninstalled platform IO extension and reinstalled and that fixed the problem. Thank you so much for leading me down the right path!