Heltec WiFi_LoRa_32_V3 Compile Error - undefined reference to `Radio'

Hi, I am trying to use PlatformIO to compile Heltec WiFi_LoRa_32_V3 but always stopped by the compile error as below about “ESP32_LoRaWAN.cpp.o:(.literal._ZN12LoRaWanClass5sleepE12eDeviceClassh+0x0): undefined reference to `Radio’”

It seems I didn’t well compile the radio for SX1262, any idea to fix this?



My PlatformIO.ini (overwrote from ESP32 dev module + Arduin0) -

platform = https://github.com/Baptou88/platform-espressif32.git
framework = arduino
board = heltec_wifi_lora_32_V3
platform_packages = framework-arduinoespressif32@https://github.com/Baptou88/arduino-esp32.git
build_flags = 
    -D RST_LoRa=14
	-D DIO0=26
    -D DIO1=33
    -D DIO2=32

lib_deps = jgromes/RadioLib@^5.5.0
build_type = debug
lib_ldf_mode = deep+
monitor_filters = esp32_exception_decoder
monitor_speed = 115200

Compile Error

Linking .pio/build/heltec_wifi_lora_32_V3/firmware.elf
/Users/junwen/.platformio/packages/toolchain-xtensa-esp32s3/bin/…/lib/gcc/xtensa-esp32s3-elf/8.4.0/…/…/…/…/xtensa-esp32s3-elf/bin/ld: .pio/build/heltec_wifi_lora_32_V3/src/ESP32_LoRaWAN.cpp.o:(.literal._ZN12LoRaWanClass5sleepE12eDeviceClassh+0x0): undefined reference to `Radio’
collect2: error: ld returned 1 exit status
*** [.pio/build/heltec_wifi_lora_32_V3/firmware.elf] Error 1

Same problem for me. I tried many things to no avail.
Did you find a solution ?

And where do I get this source file from? I need a self-contained example to loko into this.

On my side, I’m just trying to build WiFI_LoRa_32_V3_FactoryTest example from here

So, I got the needed librairies source from


and put them in the project tree (under the lib directory) to make platformio build them as static librairies (which it actually makes) and use them when linking (which it also make as the library name appears in ld command in verbose mode).

So you’re mixing Espressif Arduino-ESP32 and Heltec’s Arduino-ESP32 version :confused:

Let me see what I can do…

The file libraries/LoraWan102/src/radio/radio.c shows that the object const struct Radio_s Radio is only made available when

#if defined(WIFI_LoRa_32_V3)||defined(Wireless_Mini_Shell)

Do you have -D WIFI_LoRa_32_V3 in the build_flags of your platformio.ini to satisfy this requirement?

Thanks for the suggestion.
Actually, adding -D WIFI_LoRa_32_V3 in the build_flags generates many warning starting with

warning: "WIFI_LoRa_32_V3" redefined

and when linking several errors starting with this one

toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld: .pio/build/heltec_wifi_lora_32_V3/libaf0/libLoraWan102.a(radio.c.o):(.literal.RadioInit+0x20): undefined reference to `TimerInit'

Heltec’s core modifications are weird. They are hiding the implementation of some functions in a precompiled file rather than giving you the source code for it because… Screw developers?

In any case, from the heltec core you’ll need to copy tools\sdk\esp32\lib\libheltec.a to e.g. a new folder in your project, say precompiled_libs in the root of the project, then add


to the build_flags to link in precompiled_libs/libheltec.a.

Oh I see. Sneaky. They are doing some licencsing stuff in this library, based on the symbol names in this library. So this may not be compatible with an unmodified Arduino-ESP32 core at all if they flash additional data or have mods in other places.

Many thanks for the suggestion. Well, we’re approaching now :wink:

Before I had several undefined reference (one for Radio and several for MCu_xxxx for example) and now only one error is remaining which is

.platformio/packages/toolchain-xtensa-esp32s3@8.4.0+2021r2-patch3/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld: .pio/build/heltec_wifi_lora_32_V3/src/WiFi_LoRa_32_V3_FactoryTest.cpp.o:(.literal._Z11OnTxTimeoutv+0x0): undefined reference to `Radio

Sad, that should have been taken core of by enabling radio.c to compile its contents using the WIFI_LoRa_32_V3 define. Are you sure your C++ file is accessing this C object correctly? Do you #include <radio.h> to get the extern "C" etc definitions of this struct?

Did you clean recompile the project? (Project Tasks → Clean → then Build)

This is driving me nuts !
I only took the Heltec example unmodified and can compile it without any error with arduino-ide.
I’m trying to port to platformio environment because I prefer to use this but it’s a real pain.
Adding #include <radio.h> (actually #include <radio/radio.h> because it’s part of LoraWan102 lib doesn’t help).
And every time I CleanAll to be sure…

Compiles nicely though…

Indexing .pio/build/heltec_wifi_lora_32_V3/libFrameworkArduino.a
Linking .pio/build/heltec_wifi_lora_32_V3/firmware.elf
Retrieving maximum program size .pio/build/heltec_wifi_lora_32_V3/firmware.elf
Checking size .pio/build/heltec_wifi_lora_32_V3/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]  14.0% (used 45824 bytes from 327680 bytes)
Flash: [==        ]  21.5% (used 717065 bytes from 3342336 bytes)
Building .pio/build/heltec_wifi_lora_32_V3/firmware.bin
esptool.py v4.2.1
Creating esp32s3 image...
Merged 3 ELF sections
Successfully created esp32s3 image.
============================================ [SUCCESS] Took 8.12 seconds ============================================

I felt the #define WIFI_LoRa_32_V3 true in the pins_arduino.h was wrong so I deleted that line in C:\Users\<user>\.platformio\packages\framework-arduinoespressif32\variants\heltec_wifi_lora_32_V3\pins_arduino.h and added it via build_flags. No further mods to the core package files needed.

Test repo at GitHub - maxgerhardt/pio-heltec-lorawan-test

I somewhat messed up with my .platformio directory (not so a surprise considering the number of tests/tries I made). So I’ve deleted all the .platformio/packages/framework-arduinoespressif32* directories to force platformio to download it again cleanly
But now, with your help, finally it works !!!

Thank you very much for your help. Now I can concentrate on my real project !

Best regards.

1 Like

My updated platformio.in as below, please advise if it works

platform = https://github.com/Baptou88/platform-espressif32.git
platform_packages =
framework-arduinoespressif32@GitHub - Baptou88/arduino-esp32: Arduino core for the ESP32
board = heltec_wifi_lora_32_V3
framework = arduino
board_build.variant = heltec_wifi_lora_32_V3
build_type = debug
board_upload.maximum_size = 1310720
board_upload.maximum_data_size = 327680
board_build.target = esp32s3
board_build.mcu = esp32s3
board_build.flash_size = 8MB
board_upload.flash_size = 8MB
board_build.f_flash = 80000000L

lib_ldf_mode = deep+
monitor_speed = 115200
monitor_filters = esp32_exception_decoder

lib_deps =

build_flags =

Why both these libraries for controlling the radio? Only one library should be in charge of that.

I don’t think you should use that because its been deprecated (GitHub - HelTecAutomation/ESP32_LoRaWAN: Transplanted from Semtech LoRaWAN(https://github.com/Lora-net/LoRaMac-node) protocol to "ESP32 + Arduino" platform. Use RTC, support deep sleep, only working with ESP32 + LoRa boards made by HelTec Automation(TM). Need a unique license to use it.). I pulled the library from the Heltec core directly.

As long as I deleted “heltecautomation/ESP32_LoRaWAN@^2.1.1”, the compile process would generate the error of “undefined reference to Radio”.

You’re running into the risk of mixing two libraries then. Does that work?

When I have this “heltecautomation/ESP32_LoRaWAN@^2.1.1” in the ini, the compile was well done, but after upload the image to v3 board, it keeps rebooting, it is killing me now, can you explict how you make this ?

in any case, from the heltec core you’ll need to copy tools\sdk\esp32\lib\libheltec.a to e.g. a new folder in your project, say precompiled_libs in the root of the project, then add


to the build_flags to link in precompiled_libs/libheltec.a.

Just use it per this repo.