0

I have a Bluetooth project for an ESP32 devkit and want to compile it for an ESP32-C3. I use the newest ESP32 Arduino core as a component with esp-idf and the following configuration for PlatformIO:

[platformio]
src_dir = src
default_envs = debug

# Common build environment that is used for each of the tasks
[env]
platform = espressif32
framework = espidf

board = esp32-c3-devkitm-1

# 4 MB module version
board_upload.flash_size = 4MB
board_upload.maximum_size = 4194304
board_build.partitions = partitions.csv

# Settings for serial upload
upload_speed = 921600
upload_port = COM2

# Settings for serial console
monitor_speed = 115200
monitor_port = COM2
monitor_filters = esp32_exception_decoder

# Additional packages
platform_packages =

# Aditional build scripts for all environments to run before (`pre`) and after (`post`) the main build script
extra_scripts =

# Common build flags for all environments
build_flags =

lib_deps =
    bblanchon/ArduinoJson@^6.18.0

[env:debug]
build_type = debug

build_flags =
    ${env.build_flags}
    -D DEBUG
    -D APP_VERSION_POST='debug'

lib_deps =
    ${env.lib_deps}

extra_scripts =
    ${env.extra_scripts}

[env:release]
build_type = debug

build_flags =
    ${env.build_flags}
    -D RELEASE

lib_deps =
    ${env.lib_deps}

extra_scripts =
    ${env.extra_scripts}

I use the following toolchain:

 - framework-espidf @ 3.40401.0 (4.4.1)
 - tool-cmake @ 3.16.4
 - tool-esptoolpy @ 1.30300.0 (3.3.0)
 - tool-idf @ 1.0.1
 - tool-mconf @ 1.4060000.20190628 (406.0.0)
 - tool-ninja @ 1.9.0
 - toolchain-riscv32-esp @ 8.4.0+2021r2-patch3

But I got the following error during the linking:

.platformio/packages/toolchain-riscv32-esp/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld.exe: .pio\build\debug\esp-idf\arduino-esp32\libarduino-esp32.a(BLEAdvertising.o): in function `BLEAdvertising::start()':
components/arduino-esp32/libraries/BLE/src/BLEAdvertising.cpp:247: undefined reference to `esp_ble_gap_start_advertising'
.platformio/packages/toolchain-riscv32-esp/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld.exe: components/arduino-esp32/libraries/BLE/src/BLEAdvertising.cpp:214: undefined reference to `esp_ble_gap_config_adv_data'
.platformio/packages/toolchain-riscv32-esp/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld.exe: components/arduino-esp32/libraries/BLE/src/BLEAdvertising.cpp:225: undefined reference to `esp_ble_gap_config_adv_data'

Update 1

A verbose build outputs the following command before the error appears:

riscv32-esp-elf-g++ -o .pio\build\debug\firmware.elf -T memory.ld -u esp_app_desc -u pthread_include_pthread_impl -u pthread_include_pthread_cond_impl -u pthread_include_pthread_local_storage_impl -u pthread_include_pthread_rwlock_impl -u include_esp_phy_override -u start_app -T sections.ld 
-u __ubsan_include -T esp32c3.rom.ld -T esp32c3.rom.api.ld -T esp32c3.rom.libgcc.ld -T esp32c3.rom.newlib.ld -T esp32c3.rom.version.ld -T esp32c3.rom.newlib-time.ld -T esp32c3.rom.eco3.ld -u __assert_func -u vfs_include_syscalls_impl -T esp32c3.peripherals.ld -u app_main -u newlib_include_heap_impl -u newlib_include_syscalls_impl -u newlib_include_pthread_impl -u newlib_include_assert_impl -u __cxa_guard_dummy -u __cxx_fatal_exception --specs=nosys.specs -Wl,--Map=C:/Projects/firmware-loader/.pio/build/debug/Firmware-Loader.map -Wl,--cref -Wl,--gc-sections -Wl,--undefined=uxTopUsedPriority -Wl,--wrap=_Unwind_Backtrace -Wl,--wrap=_Unwind_DeleteException -Wl,--wrap=_Unwind_FindEnclosingFunction -Wl,--wrap=_Unwind_Find_FDE 
-Wl,--wrap=_Unwind_ForcedUnwind -Wl,--wrap=_Unwind_GetCFA -Wl,--wrap=_Unwind_GetDataRelBase -Wl,--wrap=_Unwind_GetGR -Wl,--wrap=_Unwind_GetIP -Wl,--wrap=_Unwind_GetIPInfo -Wl,--wrap=_Unwind_GetLanguageSpecificData -Wl,--wrap=_Unwind_GetRegionStart -Wl,--wrap=_Unwind_GetTextRelBase -Wl,--wrap=_Unwind_RaiseException -Wl,--wrap=_Unwind_Resume -Wl,--wrap=_Unwind_Resume_or_Rethrow -Wl,--wrap=_Unwind_SetEnableExceptionFdeSorting -Wl,--wrap=_Unwind_SetGR -Wl,--wrap=_Unwind_SetIP -Wl,--wrap=__cxa_call_unexpected -Wl,--wrap=__deregister_frame_info -Wl,--wrap=__deregister_frame_info_bases -Wl,--wrap=__gxx_personality_v0 -Wl,--wrap=__register_frame -Wl,--wrap=__register_frame_info -Wl,--wrap=__register_frame_info_bases -Wl,--wrap=__register_frame_info_table -Wl,--wrap=__register_frame_info_table_bases -Wl,--wrap=__register_frame_table -fno-lto -fno-rtti -march=rv32imc -nostartfiles -Og -g2 -ggdb2 .pio\build\debug\src\Devices\JERRY\jerry.o .pio\build\debug\src\Devices\Memory\memory.o .pio\build\debug\src\Devices\TOM\I2CM.o .pio\build\debug\src\Devices\TOM\tom.o .pio\build\debug\src\Loader\loader.o .pio\build\debug\src\Version\version.o .pio\build\debug\src\main.o -L.pio\build\debug -LC:\.platformio\packages\framework-espidf\components\bt\controller\lib_esp32c3_family\esp32c3 -LC:\.platformio\packages\framework-espidf\components\esp_wifi\lib\esp32c3 -LC:\.platformio\packages\framework-espidf\components\esp_phy\lib\esp32c3 -L.pio\build\debug\esp-idf\esp_system\ld -LC:\.platformio\packages\framework-espidf\components\esp_rom\esp32c3\ld -LC:\.platformio\packages\framework-espidf\components\esp_wifi\lib\esp32c3 -LC:\.platformio\packages\framework-espidf\components\soc\esp32c3\ld -Wl,--start-group .pio\build\debug\esp-idf\esp_ringbuf\libesp_ringbuf.a .pio\build\debug\esp-idf\asio\libasio.a .pio\build\debug\esp-idf\protobuf-c\libprotobuf-c.a .pio\build\debug\esp-idf\esp_lcd\libesp_lcd.a .pio\build\debug\esp-idf\mdns\libmdns.a .pio\build\debug\esp-idf\protocomm\libprotocomm.a .pio\build\debug\esp-idf\cbor\libcbor.a .pio\build\debug\esp-idf\cmock\libcmock.a .pio\build\debug\esp-idf\unity\libunity.a .pio\build\debug\esp-idf\bt\libbt.a .pio\build\debug\esp-idf\coap\libcoap.a .pio\build\debug\esp-idf\esp_adc_cal\libesp_adc_cal.a .pio\build\debug\esp-idf\esp_hid\libesp_hid.a .pio\build\debug\esp-idf\wear_levelling\libwear_levelling.a .pio\build\debug\esp-idf\esp_local_ctrl\libesp_local_ctrl.a .pio\build\debug\esp-idf\esp_websocket_client\libesp_websocket_client.a .pio\build\debug\esp-idf\expat\libexpat.a .pio\build\debug\esp-idf\fatfs\libfatfs.a .pio\build\debug\esp-idf\freemodbus\libfreemodbus.a .pio\build\debug\esp-idf\spiffs\libspiffs.a .pio\build\debug\esp-idf\openssl\libopenssl.a .pio\build\debug\esp-idf\libsodium\liblibsodium.a .pio\build\debug\esp-idf\jsmn\libjsmn.a .pio\build\debug\esp-idf\mqtt\libmqtt.a .pio\build\debug\esp-idf\json\libjson.a .pio\build\debug\esp-idf\wifi_provisioning\libwifi_provisioning.a .pio\build\debug\esp-idf\arduino-esp32\libarduino-esp32.a .pio\build\debug\esp-idf\RAK3172\libRAK3172.a .pio\build\debug\esp-idf\app_trace\libapp_trace.a .pio\build\debug\esp-idf\app_update\libapp_update.a .pio\build\debug\esp-idf\bootloader_support\libbootloader_support.a .pio\build\debug\esp-idf\console\libconsole.a .pio\build\debug\esp-idf\cxx\libcxx.a .pio\build\debug\esp-idf\driver\libdriver.a .pio\build\debug\esp-idf\efuse\libefuse.a .pio\build\debug\esp-idf\esp-tls\libesp-tls.a .pio\build\debug\esp-idf\esp_common\libesp_common.a .pio\build\debug\esp-idf\esp_event\libesp_event.a .pio\build\debug\esp-idf\esp_gdbstub\libesp_gdbstub.a .pio\build\debug\esp-idf\esp_http_client\libesp_http_client.a .pio\build\debug\esp-idf\esp_http_server\libesp_http_server.a .pio\build\debug\esp-idf\esp_https_ota\libesp_https_ota.a .pio\build\debug\esp-idf\esp_hw_support\libesp_hw_support.a .pio\build\debug\esp-idf\esp_ipc\libesp_ipc.a .pio\build\debug\esp-idf\esp_netif\libesp_netif.a .pio\build\debug\esp-idf\esp_phy\libesp_phy.a .pio\build\debug\esp-idf\esp_pm\libesp_pm.a .pio\build\debug\esp-idf\esp_rom\libesp_rom.a .pio\build\debug\esp-idf\esp_serial_slave_link\libesp_serial_slave_link.a .pio\build\debug\esp-idf\esp_system\libesp_system.a .pio\build\debug\esp-idf\esp_timer\libesp_timer.a .pio\build\debug\esp-idf\esp_wifi\libesp_wifi.a .pio\build\debug\esp-idf\espcoredump\libespcoredump.a .pio\build\debug\esp-idf\freertos\libfreertos.a .pio\build\debug\esp-idf\hal\libhal.a .pio\build\debug\esp-idf\heap\libheap.a .pio\build\debug\esp-idf\log\liblog.a .pio\build\debug\esp-idf\lwip\liblwip.a .pio\build\debug\esp-idf\mbedtls\libmbedtls.a .pio\build\debug\esp-idf\newlib\libnewlib.a .pio\build\debug\esp-idf\nghttp\libnghttp.a .pio\build\debug\esp-idf\nvs_flash\libnvs_flash.a .pio\build\debug\esp-idf\pthread\libpthread.a .pio\build\debug\esp-idf\riscv\libriscv.a .pio\build\debug\esp-idf\sdmmc\libsdmmc.a .pio\build\debug\esp-idf\soc\libsoc.a .pio\build\debug\esp-idf\spi_flash\libspi_flash.a .pio\build\debug\esp-idf\tcp_transport\libtcp_transport.a .pio\build\debug\esp-idf\tcpip_adapter\libtcpip_adapter.a .pio\build\debug\esp-idf\vfs\libvfs.a .pio\build\debug\esp-idf\wpa_supplicant\libwpa_supplicant.a .pio\build\debug\esp-idf\mbedtls\mbedtls\library\libmbedcrypto.a .pio\build\debug\esp-idf\mbedtls\mbedtls\library\libmbedtls.a .pio\build\debug\esp-idf\mbedtls\mbedtls\library\libmbedx509.a -lbtdm_app -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lphy -lbtbb -lgcov -lc -lm -lstdc++ -lgcc -Wl,--end-group

Update 2

It looks like libbt.a isn´t linked. May this cause this issue? How can I fix it or where do I find the required part in the build system of pio?

3
  • Is there a way to see which components have been linked or tried to be linked in PlatformIO?
    – Nick S.
    Jul 8 at 4:13
  • @NickS. please take a look at my updated question. I have inserted the last command output in verbose build.
    – Kampi
    Jul 8 at 7:00
  • CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y
    – yasiru
    Nov 4 at 11:00

1 Answer 1

-1

I have had a very similar issue just now. In short, the solution was to rename library file from .c to .cpp

Extended explanation. My platformio.ini:

[env:esp32doit-devkit-v1]
platform = espressif32
board = esp32doit-devkit-v1
framework = arduino

I am using third-party library which I build from source. This library is provided by two "lib_name.c" and "lib_name.h" files, which I have put into a lib/lib_name/ directory according to Platformio README file.

It was failing during linkage until I renamed "lib_name.c" to "lib_name.cpp", header file remained untouched.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.