Error while uploading using framework = espidf : cpu_start.c:(.text.main_task+0x84): undefined reference to `app_main'

When following the instructions here Using PlatformIO · manuelbl/ttn-esp32 Wiki · GitHub. I get the following when building, any ideas what the problem could be?

> platformio.exe run --target upload
> Processing heltec_wifi_lora_32 (platform: espressif32; board: heltec_wifi_lora_32; framework: espidf)
> ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
> CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/heltec_wifi_lora_32.html
> PLATFORM: Espressif 32 1.3.0 > Heltec WIFI LoRa 32
> HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
> PACKAGES:
>  - framework-espidf 3.30003.0 (3.0.3)
>  - tool-espotapy 1.1.2
>  - tool-esptoolpy 1.20500.0 (2.5.0)
>  - tool-mkspiffs 2.230.0 (2.30)
>  - toolchain-xtensa32 2.50200.80 (5.2.0)
> LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
> LDF Modes: Finder ~ chain, Compatibility ~ soft
> Found 0 compatible libraries
> Scanning dependencies...
> No dependencies
> Building in release mode
> Linking .pio\build\heltec_wifi_lora_32\firmware.elf
> .pio\build\heltec_wifi_lora_32\libesp32.a(cpu_start.o):(.literal.main_task+0x20): undefined reference to `app_main'
> .pio\build\heltec_wifi_lora_32\libesp32.a(cpu_start.o): In function `main_task':
> cpu_start.c:(.text.main_task+0x84): undefined reference to `app_main'
> collect2.exe: error: ld returned 1 exit status
> *** [.pio\build\heltec_wifi_lora_32\firmware.elf] Error 1

ESP-IDF is inherently a C framework, unlike Arduino. It seems like you’ve written a .cpp file in which you implemented app_main? Then:

  1. Change void app_main() { ..} to extern "C" void app_main() { .. } to avoid name-mangling
  2. Rename to the file to main.c and only write C code.

Thanks for getting back so quick. In the tuturial it says to call it cpp. point 1, its already called `extern “C” void app_main() { … }… 2. If i name it to c i get a different error.

platformio run -t upload
Processing heltec_wifi_lora_32 (platform: espressif32; board: heltec_wifi_lora_32; framework: espidf)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/heltec_wifi_lora_32.html
PLATFORM: Espressif 32 1.11.2 > Heltec WiFi LoRa 32
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-espidf 3.30300.190916 (3.3.0)
 - tool-esptoolpy 1.20600.0 (2.6.0)
 - tool-mkspiffs 2.230.0 (2.30)
 - toolchain-xtensa32 2.50200.80 (5.2.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 1 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <ttn-esp32> 2.3.2 #31b859c
Building in release mode
Compiling .pio\build\heltec_wifi_lora_32\src\main.o
Generating partitions .pio\build\heltec_wifi_lora_32\partitions.bin
Generating LD script .pio\build\heltec_wifi_lora_32\esp32_out.ld
Compiling .pio\build\heltec_wifi_lora_32\bootloader\bootloader_start.o
Compiling .pio\build\heltec_wifi_lora_32\bootloader\bootloader_support\src\bootloader_clock.o
Compiling .pio\build\heltec_wifi_lora_32\bootloader\bootloader_support\src\bootloader_common.o
In file included from src\main.c:17:0:
.pio/libdeps/heltec_wifi_lora_32/ttn-esp32/include/TheThingsNetwork.h:55:1: error: unknown type name 'class'
 class TheThingsNetwork
 ^
.pio/libdeps/heltec_wifi_lora_32/ttn-esp32/include/TheThingsNetwork.h:56:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
 {
 ^
src\main.c:44:8: error: unknown type name 'TheThingsNetwork'
 static TheThingsNetwork ttn;
        ^
src\main.c: In function 'sendMessages':
Compiling .pio\build\heltec_wifi_lora_32\bootloader\bootloader_support\src\bootloader_flash.o
src\main.c:54:9: error: unknown type name 'TTNResponseCode'
         TTNResponseCode res = ttn.transmitMessage(msgData, sizeof(msgData) - 1);
         ^
src\main.c:54:34: error: request for member 'transmitMessage' in something not a structure or union
         TTNResponseCode res = ttn.transmitMessage(msgData, sizeof(msgData) - 1);
                                  ^
src\main.c: At top level:
src\main.c:61:8: error: expected identifier or '(' before string constant
 extern "C" void app_main(void)
        ^
*** [.pio\build\heltec_wifi_lora_32\src\main.o] Error 1

I upgraded the ESP32 platform in Platform io and renamed the file back to cpp and i get error :

platformio run -t upload
Processing heltec_wifi_lora_32 (platform: espressif32; board: heltec_wifi_lora_32; framework: espidf)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/heltec_wifi_lora_32.html
PLATFORM: Espressif 32 1.11.2 > Heltec WiFi LoRa 32
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-espidf 3.30300.190916 (3.3.0)
 - tool-esptoolpy 1.20600.0 (2.6.0)
 - tool-mkspiffs 2.230.0 (2.30)
 - toolchain-xtensa32 2.50200.80 (5.2.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 1 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <ttn-esp32> 2.3.2 #31b859c
Building in release mode
Compiling .pio\build\heltec_wifi_lora_32\src\main.o
Generating partitions .pio\build\heltec_wifi_lora_32\partitions.bin
Generating LD script .pio\build\heltec_wifi_lora_32\esp32_out.ld
Compiling .pio\build\heltec_wifi_lora_32\bootloader\bootloader_start.o
Compiling .pio\build\heltec_wifi_lora_32\bootloader\bootloader_support\src\bootloader_clock.o
Compiling .pio\build\heltec_wifi_lora_32\bootloader\bootloader_support\src\bootloader_common.o
Compiling .pio\build\heltec_wifi_lora_32\bootloader\bootloader_support\src\bootloader_flash.o
src\main.cpp: In function 'void app_main()':
src\main.cpp:65:56: error: invalid conversion from 'const char*' to 'int' [-fpermissive]
     err = gpio_install_isr_service("ESP_INTR_FLAG_IRAM");
                                                        ^
In file included from C:/users/alex.kelly/.platformio/packages/framework-espidf/components/esp32/include/esp_sleep.h:19:0,
                 from C:/users/alex.kelly/.platformio/packages/framework-espidf/components/esp32/include/esp_system.h:21,
                 from C:/users/alex.kelly/.platformio/packages/framework-espidf/components/freertos/include/freertos/portable.h:126,
                 from C:/users/alex.kelly/.platformio/packages/framework-espidf/components/freertos/include/freertos/FreeRTOS.h:105,
                 from src\main.cpp:13:
C:/users/alex.kelly/.platformio/packages/framework-espidf/components/driver/include/driver/gpio.h:470:11: note:   initializing argument 1 of 'esp_err_t gpio_install_isr_service(int)'
 esp_err_t gpio_install_isr_service(int intr_alloc_flags);
           ^
Compiling .pio\build\heltec_wifi_lora_32\bootloader\bootloader_support\src\bootloader_init.o
*** [.pio\build\heltec_wifi_lora_32\src\main.o] Error 1
================================================================================================ [FAILED] Took 5.87 seconds ================================================================================================PS C:\IOT\Github\Personal\Heltec_hello_world> 

Any ideas?

Here’s my code :

Well the error message is correct, the function does expect an int and not a const char* (docs). The error is also already reported in the original repo: Problems with gpio_install_isr_service / ESP_INTR_FLAG_IRAM · Issue #24 · manuelbl/ttn-esp32 · GitHub

There seems to be a more up-to-date version in Esp32LoraBoard/src/main.cpp at master · vrees/Esp32LoraBoard · GitHub.