PlatformIO Community

Force RTTI from library?

Hello,

Is it possible to force RTTI to be enabled from library level (library.json?) on whole project.?

I’m working on a library that uses a lot of templates and requires RTTI. I know that there is build_unflags parameter but it only seems to work when set in platformio.ini (project config)

Regards,
Chris

You can specify an extraScript in the library.json in which you can manipulate the global build environment with whatever compiler and linker flags you like, including adding -frtti and removing possible -fno-rtti flags.

I do similiar things in my FreeRTOS build script.

There seems to be the problem though that in a library build script, you cannot modify the projenv environment which used to build sources in src/. I’ve actually seen this problem being worked around by some library by telling users to add extra_script lines to their platformio.ini and link to the library itself, e.g., like here.

The following works with a platformio.ini modification:

[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
framework = arduino
build_unflags = -fno-rtti

and the builder script of the library

Import("env")
global_env = DefaultEnvironment()
for e in (env, global_env):
    try:
        # key may or may not exist
        e['CXXFLAGS'].remove("-fno-rtti")
    except:
        pass
    e['CXXFLAGS'].append("-frtti")

It looks like partially working. If lib uses RTTI features, then it’s ok, but when calling dynamic_cast from project src directory, then getting "error: ‘dynamic_cast’ not permitted with -fno-rtti"

build_unflags = -fno-rtti works perfectly but it’s not clean solution

Right, I’ve opened issue Allow post scripts in library.json · Issue #4305 · platformio/platformio-core · GitHub about this. Until then there’s that workaround.

That’s cool that you’ve reported that, thanks!

I’m a little bit confused about global_env. They say:

  1. Flags passed to env using PRE-type script will affect projenv too.

Can library script work like PRE-type script?

https://docs.platformio.org/en/latest/scripting/construction_environments.html

Interesting, the libraries are I think handled conceptually as pre-scripts, but the problem is that the -fno-rtti gets added at a later stage through the Arduino-ESP8266 build script so the library script cannot remove what is not yet there.

I’ve also tried adding e["BUILD_UNFLAGS"] = ["-fno-rtti"] in various forms in hopes that this “survives” and is applied later, but no luck.

Could you re-test with the latest development version of PlatformIO Core? Open PlatformIO Core CLI and type

pio upgrade --dev

See example in docs extraScript — PlatformIO latest documentation

Does it work now?

Following script together with --dev version does the job!

Import("projenv", "env")

for e in (env, DefaultEnvironment(), projenv):
	e.ProcessUnFlags("-fno-rtti")
1 Like

This is somewhat strange but I’ve had some troubles in my two projects:

  • One using ESP32 - WiFiClient linking errors, removing DefaultEnvironment from ProcessUnFlags (see previous script) fixed that issue.
c:/users/chris/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\esp32dev\lib0b0\libWiFi.a(WiFiClient.cpp.o):(.rodata._ZTI6Client[_ZTI6Client]+0x8): undefined reference to `typeinfo for Stream'
c:/users/chris/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\esp32dev\lib0b0\libWiFi.a(WiFiUdp.cpp.o):(.rodata._ZTI3UDP[_ZTI3UDP]+0x8): undefined reference to `typeinfo for Stream'
c:/users/chris/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\esp32dev\lib5ab\libFS.a(FS.cpp.o):(.rodata._ZTIN2fs4FileE[_ZTIN2fs4FileE]+0x8): undefined reference to `typeinfo for Stream'
c:/users/chris/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\esp32dev\lib0b0\libWiFi.a(WiFiServer.cpp.o):(.rodata._ZTI6Server[_ZTI6Server]+0x8): undefined reference to `typeinfo for Print'
  • One using ESP8266 - unable to fix atm:
c:/users/chris/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/10.3.0/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\esp8266dev\lib0ba\libksIotFrameworkLib.a(ksMqttConnector.cpp.o):(.rodata._ZTIN7BearSSL16WiFiClientSecureE[_ZTIN7BearSSL16WiFiClientSecureE]+0x8): undefined reference to `_ZTI10WiFiClient'

When using build_unflags from platformio.ini there are no issues.

Could you build a project in verbose mode? Do you see any files where a flag was not removed?

Of course, here you go :slight_smile:

Unflag rtti script:

Import("projenv", "env")

for e in (env, DefaultEnvironment(), projenv):
	e.ProcessUnFlags("-fno-rtti")

The project is open source → https://github.com/cziter15/pelletmon, so feel free to checkout and debug. Inside platformio.ini you must remove unflag that I’ve added manually to trigger issue. Inside ksIotFrameworkLib you have to add script to unflag rtti.

> Executing task: C:\Users\chris\.platformio\penv\Scripts\platformio.exe run --verbose --environment esp32dev <

Processing esp32dev (platform: espressif32; board: esp32dev; framework: arduino; lib_deps: ksIotFrameworkLib=https://github.com/cziter15/ksIotFrameworkLib, esp32_can=https://github.com/collin80/esp32_can, can_common=https://github.com/collin80/can_common; board_build.f_cpu: 80000000L; board_build.f_flash: 80000000L; board_build.flash_mode: qio; board_build.loop_core: 0; board_build.event_core: 1; upload_protocol: espota; upload_port: PelletMon.local; upload_flags: --port=3232, --auth=ota_ksiotframework)
-----------------------------------------------------------------------------------
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 (4.4.0) > Espressif ESP32 Dev Module
HARDWARE: ESP32 80MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, 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.20003.220613 (2.0.3)
 - tool-esptoolpy @ 1.30300.0 (3.3.0)
 - tool-openocd-esp32 @ 2.1100.20220411 (11.0)
 - toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch3
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 37 compatible libraries
Scanning dependencies...
Dependency Graph
|-- ksIotFrameworkLib @ 1.0.0+sha.01418ca (License: MIT, URI: git+https://github.com/cziter15/ksIotFrameworkLib, Path: D:\ProjektyKicad\pelletmon\firmware\.pio\libdeps\esp32dev\ksIotFrameworkLib)
|   |-- WiFiManager @ 2.0.11-beta+sha.9c7fed4 (License: Unknown, URI: git+https://github.com/tzapu/WiFiManager, Path: D:\ProjektyKicad\pelletmon\firmware\.pio\libdeps\esp32dev\WiFiManager)
|   |   |-- DNSServer @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\DNSServer)
|   |   |   |-- WiFi @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\WiFi)
|   |   |-- ESPmDNS @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\ESPmDNS)
|   |   |   |-- WiFi @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\WiFi)
|   |   |-- Update @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\Update)
|   |   |-- WebServer @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\WebServer)
|   |   |   |-- WiFi @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\WiFi)
|   |   |   |-- FS @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\FS)
|   |   |-- WiFi @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\WiFi)
|   |-- PubSubClient @ 2.8.0+sha.2d228f2 (License: Unknown, URI: git+https://github.com/knolleary/pubsubclient, Path: D:\ProjektyKicad\pelletmon\firmware\.pio\libdeps\esp32dev\PubSubClient)
|   |-- WiFi @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\WiFi)
|   |-- WiFiClientSecure @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\WiFiClientSecure)
|   |   |-- WiFi @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\WiFi)
|   |-- FS @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\FS)
|   |-- SPIFFS @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\SPIFFS)
|   |   |-- FS @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\FS)
|-- ESP32_CAN @ 0.2.5+sha.0fb9878 (License: Unknown, URI: git+https://github.com/collin80/esp32_can, Path: D:\ProjektyKicad\pelletmon\firmware\.pio\libdeps\esp32dev\esp32_can)
|   |-- can_common @ 0.3.0+sha.07605a2 (License: Unknown, URI: git+https://github.com/collin80/can_common, Path: D:\ProjektyKicad\pelletmon\firmware\.pio\libdeps\esp32dev\can_common)
|   |-- SPI @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\SPI)
|-- can_common @ 0.3.0+sha.07605a2 (License: Unknown, URI: git+https://github.com/collin80/can_common, Path: D:\ProjektyKicad\pelletmon\firmware\.pio\libdeps\esp32dev\can_common)
|-- ArduinoOTA @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\ArduinoOTA)
|   |-- Update @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\Update)
|   |-- WiFi @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\WiFi)
|   |-- ESPmDNS @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\ESPmDNS)
|   |   |-- WiFi @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\WiFi)
Building in release mode
xtensa-esp32-elf-g++ -o .pio\build\esp32dev\firmware.elf -fno-rtti -mlongcalls -Wno-frame-address -Wl,--cref -Wl,--gc-sections -fno-lto -Wl,--wrap=longjmp -Wl,--undefined=uxTopUsedPriority -T esp32.rom.redefined.ld -T memory.ld -T sections.ld -T esp32.rom.ld -T esp32.rom.api.ld -T esp32.rom.libgcc.ld -T esp32.rom.newlib-data.ld -T esp32.rom.syscalls.ld -T esp32.peripherals.ld -u ld_include_hli_vectors_bt -u _Z5setupv -u _Z4loopv -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 ld_include_highint_hdl -u start_app -u start_app_other_cores -u __ubsan_include -u __assert_func -u vfs_include_syscalls_impl -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 -Wl,-Map="D:\ProjektyKicad\pelletmon\firmware\.pio\build\esp32dev\firmware.map" .pio\build\esp32dev\src\apps\config\PelletMonConfig.cpp.o .pio\build\esp32dev\src\apps\pelletmon\PelletMon.cpp.o .pio\build\esp32dev\src\apps\pelletmon\components\VideNetClient.cpp.o .pio\build\esp32dev\src\apps\pelletmon\videnet\VideNet.cpp.o .pio\build\esp32dev\src\main.cpp.o -L.pio\build\esp32dev -LC:\Users\chris\.platformio\packages\framework-arduinoespressif32\tools\sdk\esp32\lib -LC:\Users\chris\.platformio\packages\framework-arduinoespressif32\tools\sdk\esp32\ld -LC:\Users\chris\.platformio\packages\framework-arduinoespressif32\tools\sdk\esp32\qspi_qspi -Wl,--start-group .pio\build\esp32dev\lib0b0\libWiFi.a .pio\build\esp32dev\lib867\libDNSServer.a .pio\build\esp32dev\lib0d3\libESPmDNS.a .pio\build\esp32dev\lib169\libUpdate.a .pio\build\esp32dev\lib5ab\libFS.a .pio\build\esp32dev\lib03a\libWebServer.a .pio\build\esp32dev\lib6cb\libWiFiManager.a .pio\build\esp32dev\lib797\libPubSubClient.a .pio\build\esp32dev\lib5c4\libWiFiClientSecure.a .pio\build\esp32dev\lib444\libSPIFFS.a .pio\build\esp32dev\lib6db\libksIotFrameworkLib.a .pio\build\esp32dev\libe14\libcan_common.a .pio\build\esp32dev\lib418\libSPI.a .pio\build\esp32dev\lib4e4\libesp32_can.a .pio\build\esp32dev\lib825\libArduinoOTA.a .pio\build\esp32dev\libFrameworkArduino.a -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lasio -lbt -lcbor -lunity -lcmock -lcoap -lnghttp -lesp-tls -lesp_adc_cal -lesp_hid -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lesp_lcd -lprotobuf-c -lprotocomm -lmdns -lesp_local_ctrl -lsdmmc -lesp_serial_slave_link -lesp_websocket_client -lexpat -lwear_levelling -lfatfs -lfreemodbus -ljsmn -ljson -llibsodium -lmqtt -lopenssl -lperfmon -lspiffs -lulp -lwifi_provisioning -lbutton -lrmaker_common -ljson_parser -ljson_generator -lesp_schedule -lesp_rainmaker -lqrcode -lws2812_led -lesp-dsp -lesp-sr -lesp32-camera -lesp_littlefs -lfb_gfx -lasio -lcbor -lcmock -lunity -lcoap -lesp_lcd -lesp_websocket_client -lexpat -lfreemodbus -ljsmn -llibsodium -lperfmon -lesp_adc_cal -lesp_hid -lfatfs -lwear_levelling -lopenssl -lesp_rainmaker -lesp_local_ctrl -lwifi_provisioning -lprotocomm -lbt -lbtdm_app -lprotobuf-c -lmdns -lrmaker_common -lmqtt -ljson_parser -ljson_generator -lesp_schedule -lqrcode -lcat_face_detect -lhuman_face_detect -lcolor_detect -lmfn -ldl -lwakenet -lmultinet -lesp_audio_processor -lesp_audio_front_end -lesp-sr -lwakenet -lmultinet -lesp_audio_processor -lesp_audio_front_end -ljson -lspiffs -ldl_lib -lc_speech_features -lhilexin_wn5 -lhilexin_wn5X2 -lhilexin_wn5X3 -lnihaoxiaozhi_wn5 -lnihaoxiaozhi_wn5X2 -lnihaoxiaozhi_wn5X3 -lnihaoxiaoxin_wn5X3 -lcustomized_word_wn5 -lmultinet2_ch -lesp_tts_chinese -lvoice_set_xiaole -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lphy -lrtc -lesp_phy -lphy -lrtc -lesp_phy -lphy -lrtc -lxt_hal -lm -lnewlib -lstdc++ -lpthread -lgcc -lcxx -lapp_trace -lgcov -lapp_trace -lgcov -lc -Wl,--end-group
c:/users/chris/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\esp32dev\lib0b0\libWiFi.a(WiFiClient.cpp.o):(.rodata._ZTI6Client[_ZTI6Client]+0x8): undefined reference to `typeinfo for Stream'
c:/users/chris/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\esp32dev\lib0b0\libWiFi.a(WiFiUdp.cpp.o):(.rodata._ZTI3UDP[_ZTI3UDP]+0x8): undefined reference to `typeinfo for Stream'
c:/users/chris/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\esp32dev\lib5ab\libFS.a(FS.cpp.o):(.rodata._ZTIN2fs4FileE[_ZTIN2fs4FileE]+0x8): undefined reference to `typeinfo for Stream'
c:/users/chris/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\esp32dev\lib0b0\libWiFi.a(WiFiServer.cpp.o):(.rodata._ZTI6Server[_ZTI6Server]+0x8): undefined reference to `typeinfo for Print'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\esp32dev\firmware.elf] Error 1

Hm it is also in the env[“LINKFLAGS”].

Try

Import("projenv", "env")

for e in (env, DefaultEnvironment(), projenv):
    e.ProcessUnFlags("-fno-rtti")
    e["LINKFLAGS"] = [x for x in e["LINKFLAGS"] if x != "-fno-rtti"]

Doesn’t help. Looks like flag is already removed by ProcessUnFlags but xtensa linker is still running with -fno-rtti switch. Maybe these flags are applied later?

We improved ProcessUnFlags yesterday. Could you try pio upgrade --dev. Does it work now?

6.0.3a7 Unfortunately didn’t help.

Using script:

Import("projenv", "env")

print("doing unflag..................")

for e in (env, DefaultEnvironment(), projenv):
    e.ProcessUnFlags("-fno-rtti")
 Executing task: C:\Users\chris\.platformio\penv\Scripts\platformio.exe run --verbose --environment esp32dev <

Processing esp32dev (platform: espressif32; board: esp32dev; framework: arduino; lib_deps: ksIotFrameworkLib=https://github.com/cziter15/ksIotFrameworkLib, esp32_can=https://github.com/collin80/esp32_can, can_common=https://github.com/collin80/can_common; board_build.f_cpu: 80000000L; board_build.f_flash: 80000000L; board_build.flash_mode: qio; board_build.loop_core: 0; board_build.event_core: 1; upload_protocol: espota; upload_port: PelletMon.local; upload_flags: --port=3232, --auth=ota_ksiotframework)
---------------------------------------------------------------------------------------------------------------------------------------------------------
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 (4.4.0) > Espressif ESP32 Dev Module
HARDWARE: ESP32 80MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, 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.20003.220613 (2.0.3) 
 - tool-esptoolpy @ 1.30300.0 (3.3.0) 
 - tool-openocd-esp32 @ 2.1100.20220411 (11.0) 
 - toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch3
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
doing unflag..................
Found 37 compatible libraries
Scanning dependencies...
Dependency Graph
|-- ksIotFrameworkLib @ 1.0.0+sha.01418ca (License: MIT, URI: git+https://github.com/cziter15/ksIotFrameworkLib, Path: D:\ProjektyKicad\pelletmon\firmware\.pio\libdeps\esp32dev\ksIotFrameworkLib)
|   |-- WiFiManager @ 2.0.11-beta+sha.9c7fed4 (License: Unknown, URI: git+https://github.com/tzapu/WiFiManager, Path: D:\ProjektyKicad\pelletmon\firmware\.pio\libdeps\esp32dev\WiFiManager)
|   |   |-- DNSServer @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\DNSServer)
|   |   |   |-- WiFi @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\WiFi)
|   |   |-- ESPmDNS @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\ESPmDNS)
|   |   |   |-- WiFi @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\WiFi)
|   |   |-- Update @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\Update)
|   |   |-- WebServer @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\WebServer)
|   |   |   |-- WiFi @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\WiFi)
|   |   |   |-- FS @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\FS)
|   |   |-- WiFi @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\WiFi)
|   |-- PubSubClient @ 2.8.0+sha.2d228f2 (License: Unknown, URI: git+https://github.com/knolleary/pubsubclient, Path: D:\ProjektyKicad\pelletmon\firmware\.pio\libdeps\esp32dev\PubSubClient)
|   |-- WiFi @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\WiFi)
|   |-- WiFiClientSecure @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\WiFiClientSecure)   
|   |   |-- WiFi @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\WiFi)
|   |-- FS @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\FS)
|   |-- SPIFFS @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\SPIFFS)
|   |   |-- FS @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\FS)
|-- ESP32_CAN @ 0.2.5+sha.0fb9878 (License: Unknown, URI: git+https://github.com/collin80/esp32_can, Path: D:\ProjektyKicad\pelletmon\firmware\.pio\libdeps\esp32dev\esp32_can)
|   |-- can_common @ 0.3.0+sha.07605a2 (License: Unknown, URI: git+https://github.com/collin80/can_common, Path: D:\ProjektyKicad\pelletmon\firmware\.pio\libdeps\esp32dev\can_common)
|   |-- SPI @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\SPI)
|-- can_common @ 0.3.0+sha.07605a2 (License: Unknown, URI: git+https://github.com/collin80/can_common, Path: D:\ProjektyKicad\pelletmon\firmware\.pio\libdeps\esp32dev\can_common)
|-- ArduinoOTA @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\ArduinoOTA)
|   |-- Update @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\Update)
|   |-- WiFi @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\WiFi)
|   |-- ESPmDNS @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\ESPmDNS)
|   |   |-- WiFi @ 2.0.0 (License: Unknown, Path: C:\Users\chris\.platformio\packages\framework-arduinoespressif32\libraries\WiFi)
Building in release mode
xtensa-esp32-elf-g++ -o .pio\build\esp32dev\firmware.elf -fno-rtti -mlongcalls -Wno-frame-address -Wl,--cref -Wl,--gc-sections -fno-lto -Wl,--wrap=longjmp -Wl,--undefined=uxTopUsedPriority -T esp32.rom.redefined.ld -T memory.ld -T sections.ld -T esp32.rom.ld -T esp32.rom.api.ld -T esp32.rom.libgcc.ld -T esp32.rom.newlib-data.ld -T esp32.rom.syscalls.ld -T esp32.peripherals.ld -u ld_include_hli_vectors_bt -u _Z5setupv -u _Z4loopv -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 ld_include_highint_hdl -u start_app -u start_app_other_cores -u __ubsan_include -u __assert_func -u vfs_include_syscalls_impl -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 -Wl,-Map="D:\ProjektyKicad\pelletmon\firmware\.pio\build\esp32dev\firmware.map" .pio\build\esp32dev\src\apps\config\PelletMonConfig.cpp.o .pio\build\esp32dev\src\apps\pelletmon\PelletMon.cpp.o .pio\build\esp32dev\src\apps\pelletmon\components\VideNetClient.cpp.o .pio\build\esp32dev\src\apps\pelletmon\videnet\VideNet.cpp.o .pio\build\esp32dev\src\main.cpp.o -L.pio\build\esp32dev -LC:\Users\chris\.platformio\packages\framework-arduinoespressif32\tools\sdk\esp32\lib -LC:\Users\chris\.platformio\packages\framework-arduinoespressif32\tools\sdk\esp32\ld -LC:\Users\chris\.platformio\packages\framework-arduinoespressif32\tools\sdk\esp32\qspi_qspi -Wl,--start-group .pio\build\esp32dev\lib0b0\libWiFi.a .pio\build\esp32dev\lib867\libDNSServer.a .pio\build\esp32dev\lib0d3\libESPmDNS.a .pio\build\esp32dev\lib169\libUpdate.a .pio\build\esp32dev\lib5ab\libFS.a .pio\build\esp32dev\lib03a\libWebServer.a .pio\build\esp32dev\lib6cb\libWiFiManager.a .pio\build\esp32dev\lib797\libPubSubClient.a .pio\build\esp32dev\lib5c4\libWiFiClientSecure.a .pio\build\esp32dev\lib444\libSPIFFS.a .pio\build\esp32dev\lib6db\libksIotFrameworkLib.a .pio\build\esp32dev\libe14\libcan_common.a .pio\build\esp32dev\lib418\libSPI.a .pio\build\esp32dev\lib4e4\libesp32_can.a .pio\build\esp32dev\lib825\libArduinoOTA.a .pio\build\esp32dev\libFrameworkArduino.a -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lasio -lbt -lcbor -lunity -lcmock -lcoap -lnghttp -lesp-tls -lesp_adc_cal -lesp_hid -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lesp_lcd -lprotobuf-c -lprotocomm -lmdns -lesp_local_ctrl -lsdmmc -lesp_serial_slave_link -lesp_websocket_client -lexpat -lwear_levelling -lfatfs -lfreemodbus -ljsmn -ljson -llibsodium -lmqtt -lopenssl -lperfmon -lspiffs -lulp -lwifi_provisioning -lbutton -lrmaker_common -ljson_parser -ljson_generator -lesp_schedule -lesp_rainmaker -lqrcode -lws2812_led -lesp-dsp -lesp-sr -lesp32-camera -lesp_littlefs -lfb_gfx -lasio -lcbor -lcmock -lunity -lcoap -lesp_lcd -lesp_websocket_client -lexpat -lfreemodbus -ljsmn -llibsodium -lperfmon -lesp_adc_cal -lesp_hid -lfatfs -lwear_levelling -lopenssl -lesp_rainmaker -lesp_local_ctrl -lwifi_provisioning -lprotocomm -lbt -lbtdm_app -lprotobuf-c -lmdns -lrmaker_common -lmqtt -ljson_parser -ljson_generator -lesp_schedule -lqrcode -lcat_face_detect -lhuman_face_detect -lcolor_detect -lmfn -ldl -lwakenet -lmultinet -lesp_audio_processor -lesp_audio_front_end -lesp-sr -lwakenet -lmultinet -lesp_audio_processor -lesp_audio_front_end -ljson -lspiffs -ldl_lib -lc_speech_features -lhilexin_wn5 -lhilexin_wn5X2 -lhilexin_wn5X3 -lnihaoxiaozhi_wn5 -lnihaoxiaozhi_wn5X2 -lnihaoxiaozhi_wn5X3 -lnihaoxiaoxin_wn5X3 -lcustomized_word_wn5 -lmultinet2_ch -lesp_tts_chinese -lvoice_set_xiaole -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lphy -lrtc -lesp_phy -lphy -lrtc -lesp_phy -lphy -lrtc -lxt_hal -lm -lnewlib -lstdc++ -lpthread -lgcc -lcxx -lapp_trace -lgcov -lapp_trace -lgcov -lc -Wl,--end-group
c:/users/chris/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\esp32dev\lib0b0\libWiFi.a(WiFiClient.cpp.o):(.rodata._ZTI6Client[_ZTI6Client]+0x8): undefined reference to `typeinfo for Stream'
c:/users/chris/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\esp32dev\lib0b0\libWiFi.a(WiFiUdp.cpp.o):(.rodata._ZTI3UDP[_ZTI3UDP]+0x8): undefined reference to `typeinfo for Stream'
c:/users/chris/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\esp32dev\lib5ab\libFS.a(FS.cpp.o):(.rodata._ZTIN2fs4FileE[_ZTIN2fs4FileE]+0x8): undefined reference to `typeinfo for Stream'
c:/users/chris/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\esp32dev\lib0b0\libWiFi.a(WiFiServer.cpp.o):(.rodata._ZTI6Server[_ZTI6Server]+0x8): undefined reference to `typeinfo for Print'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\esp32dev\firmware.elf] Error 1

I’ve tried to manually modify env’s BUILD_UNFLAGS, it looks like everything is modiffied inside env as expected, but still xtensa linker (xtensa-esp32-elf-g++) has -fno-rtti passed there in command line.

Just as a quick counter-check, if you go into the Arduino-ESP32 builder script locally at C:\Users\<user>\.platformio\packages\framework-ardinoespressif32\tools\platformio-build-esp32.py and remove -fno-rtti from the LINKFLAGS array, does it build correctly or still fail?

Removing nortti from linkflags and cxxflags inside platformio-build-esp32.py fixes the problem, it’s not a solution anyway.

This is a bug in ESP32 build sciprt. See arduino-esp32/platformio-build-esp32s3.py at master · espressif/arduino-esp32 · GitHub

We will make PR to that repo. Meanwhile, we updated the package in the registry. Could you navigate to your project and type pio pkg update? It should work now.

1 Like