Serial.begin() leads to build errors

Seysin
Posts: 3
Joined: Tue Oct 25, 2022 1:18 am

Serial.begin() leads to build errors

Postby Seysin » Sat Nov 15, 2025 1:15 pm

As soon as I add

Code: Select all

Serial.begin(115200);
in my project i get a bunch of build errors (see below). Without that line everything works as it should. Other Arduino functions work fine. In an empty project just for testing Arduino Serial printing it also works without a problem. Tried to solve it with Claude but Claude is just making up non-existing CMakeLists- or SDKConfig-Options.

Here are the errors:

Code: Select all

[7/9] Linking CXX executable lvgl_demo_v9.elf
FAILED: lvgl_demo_v9.elf
C:\WINDOWS\system32\cmd.exe /C "cd . && D:\.espressif\tools\riscv32-esp-elf\esp-14.2.0_20241119\riscv32-esp-elf\bin\riscv32-esp-elf-g++.exe -march=rv32imafc_zicsr_zifencei_xesppie -mabi=ilp32f -nostartfiles -march=rv32imafc_zicsr_zifencei_xesppie -mabi=ilp32f    -Wl,--cref -Wl,--defsym=IDF_TARGET_ESP32P4=0 -Wl,--Map=C:/Users/<USER>/ESP-IDF-Projects/<PROJECT>/build/lvgl_demo_v9.map -Wl,--no-warn-rwx-segments -Wl,--orphan-handling=warn -fno-rtti -fno-lto -Wl,--gc-sections -Wl,--warn-common -T rom.api.ld -T esp32p4.peripherals.ld -T esp32p4.rom.ld -T esp32p4.rom.api.ld -T esp32p4.rom.rvfp.ld -T esp32p4.rom.wdt.ld -T esp32p4.rom.systimer.ld -T esp32p4.rom.version.ld -T esp32p4.rom.libc.ld -T esp32p4.rom.libc-suboptimal_for_misaligned_mem.ld -T esp32p4.rom.newlib.ld -T memory.ld -T sections.ld -Wl,--enable-non-contiguous-regions @CMakeFiles\lvgl_demo_v9.elf.rsp -o lvgl_demo_v9.elf && cd ."
D:/.espressif/tools/riscv32-esp-elf/esp-14.2.0_20241119/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/14.2.0/../../../../riscv32-esp-elf/bin/ld.exe: error: --enable-non-contiguous-regions discards section `.sdata.periph_spinlock' from `esp-idf/esp_hw_support/libesp_hw_support.a(periph_ctrl.c.obj)'
D:/.espressif/tools/riscv32-esp-elf/esp-14.2.0_20241119/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/14.2.0/../../../../riscv32-esp-elf/bin/ld.exe: error: --enable-non-contiguous-regions discards section `.sdata.rtc_spinlock' from `esp-idf/esp_hw_support/libesp_hw_support.a(rtc_module.c.obj)'
D:/.espressif/tools/riscv32-esp-elf/esp-14.2.0_20241119/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/14.2.0/../../../../riscv32-esp-elf/bin/ld.exe: error: --enable-non-contiguous-regions discards section `.sdata.spinlock_rtc_deep_sleep' from `esp-idf/esp_hw_support/libesp_hw_support.a(sleep_modes.c.obj)'
D:/.espressif/tools/riscv32-esp-elf/esp-14.2.0_20241119/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/14.2.0/../../../../riscv32-esp-elf/bin/ld.exe: error: --enable-non-contiguous-regions discards section `.sdata.s_psram_best_delayline' from `esp-idf/esp_hw_support/libesp_hw_support.a(mspi_timing_by_dqs.c.obj)'
D:/.espressif/tools/riscv32-esp-elf/esp-14.2.0_20241119/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/14.2.0/../../../../riscv32-esp-elf/bin/ld.exe: error: --enable-non-contiguous-regions discards section `.sdata.s_psram_best_phase' from `esp-idf/esp_hw_support/libesp_hw_support.a(mspi_timing_by_dqs.c.obj)'
D:/.espressif/tools/riscv32-esp-elf/esp-14.2.0_20241119/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/14.2.0/../../../../riscv32-esp-elf/bin/ld.exe: error: --enable-non-contiguous-regions discards section `.sdata.mux' from `esp-idf/esp_hw_support/libesp_hw_support.a(regi2c_ctrl.c.obj)'
D:/.espressif/tools/riscv32-esp-elf/esp-14.2.0_20241119/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/14.2.0/../../../../riscv32-esp-elf/bin/ld.exe: error: --enable-non-contiguous-regions discards section `.sdata.pau_context.0' from `esp-idf/esp_hw_support/libesp_hw_support.a(pau_regdma.c.obj)'
D:/.espressif/tools/riscv32-esp-elf/esp-14.2.0_20241119/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/14.2.0/../../../../riscv32-esp-elf/bin/ld.exe: error: --enable-non-contiguous-regions discards section `.sdata.xKernelLock' from `esp-idf/freertos/libfreertos.a(tasks.c.obj)'
D:/.espressif/tools/riscv32-esp-elf/esp-14.2.0_20241119/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/14.2.0/../../../../riscv32-esp-elf/bin/ld.exe: error: --enable-non-contiguous-regions discards section `.sdata.lock_init_spinlock' from `esp-idf/newlib/libnewlib.a(locks.c.obj)'
D:/.espressif/tools/riscv32-esp-elf/esp-14.2.0_20241119/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/14.2.0/../../../../riscv32-esp-elf/bin/ld.exe: error: --enable-non-contiguous-regions discards section `.sdata.s_keys_lock' from `esp-idf/pthread/libpthread.a(pthread_local_storage.c.obj)'
D:/.espressif/tools/riscv32-esp-elf/esp-14.2.0_20241119/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/14.2.0/../../../../riscv32-esp-elf/bin/ld.exe: error: --enable-non-contiguous-regions discards section `.sdata.s_time_update_lock' from `esp-idf/esp_timer/libesp_timer.a(esp_timer_impl_common.c.obj)'
D:/.espressif/tools/riscv32-esp-elf/esp-14.2.0_20241119/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/14.2.0/../../../../riscv32-esp-elf/bin/ld.exe: error: --enable-non-contiguous-regions discards section `.sdata.s_registered_select_lock' from `esp-idf/esp_driver_uart/libesp_driver_uart.a(uart_vfs.c.obj)'
D:/.espressif/tools/riscv32-esp-elf/esp-14.2.0_20241119/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/14.2.0/../../../../riscv32-esp-elf/bin/ld.exe: error: --enable-non-contiguous-regions discards section `.sdata.uart_selectlock' from `esp-idf/esp_driver_uart/libesp_driver_uart.a(uart.c.obj)'
D:/.espressif/tools/riscv32-esp-elf/esp-14.2.0_20241119/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/14.2.0/../../../../riscv32-esp-elf/bin/ld.exe: error: --enable-non-contiguous-regions discards section `.sdata.s_registered_select_lock' from `esp-idf/esp_driver_usb_serial_jtag/libesp_driver_usb_serial_jtag.a(usb_serial_jtag_vfs.c.obj)'
D:/.espressif/tools/riscv32-esp-elf/esp-14.2.0_20241119/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/14.2.0/../../../../riscv32-esp-elf/bin/ld.exe: error: --enable-non-contiguous-regions discards section `.sdata.chip_type' from `esp-idf/espressif__esp_hosted/libespressif__esp_hosted.a(transport_drv.c.obj)'
D:/.espressif/tools/riscv32-esp-elf/esp-14.2.0_20241119/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/14.2.0/../../../../riscv32-esp-elf/bin/ld.exe: error: --enable-non-contiguous-regions discards section `.sdata.g_h' from `esp-idf/espressif__esp_hosted/libespressif__esp_hosted.a(port_esp_hosted_host_os.c.obj)'
D:/.espressif/tools/riscv32-esp-elf/esp-14.2.0_20241119/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/14.2.0/../../../../riscv32-esp-elf/bin/ld.exe: error: --enable-non-contiguous-regions discards section `.sdata.session_mobile' from `esp-idf/main/libmain.a(lv_demo_widgets_analytics.c.obj)'
D:/.espressif/tools/riscv32-esp-elf/esp-14.2.0_20241119/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/14.2.0/../../../../riscv32-esp-elf/bin/ld.exe: error: --enable-non-contiguous-regions discards section `.sdata.session_tablet' from `esp-idf/main/libmain.a(lv_demo_widgets_analytics.c.obj)'
D:/.espressif/tools/riscv32-esp-elf/esp-14.2.0_20241119/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/14.2.0/../../../../riscv32-esp-elf/bin/ld.exe: error: --enable-non-contiguous-regions discards section `.sdata.session_desktop' from `esp-idf/main/libmain.a(lv_demo_widgets_analytics.c.obj)'
D:/.espressif/tools/riscv32-esp-elf/esp-14.2.0_20241119/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/14.2.0/../../../../riscv32-esp-elf/bin/ld.exe: error: --enable-non-contiguous-regions discards section `.sdata.grid_main_col_dsc.5' from `esp-idf/main/libmain.a(lv_demo_widgets_profile.c.obj)'
D:/.espressif/tools/riscv32-esp-elf/esp-14.2.0_20241119/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/14.2.0/../../../../riscv32-esp-elf/bin/ld.exe: error: --enable-non-contiguous-regions discards section `.sdata.grid1_col_dsc.3' from `esp-idf/main/libmain.a(lv_demo_widgets_shop.c.obj)'
D:/.espressif/tools/riscv32-esp-elf/esp-14.2.0_20241119/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/14.2.0/../../../../riscv32-esp-elf/bin/ld.exe: error: --enable-non-contiguous-regions discards section `.sdata._ZL13tx_timeout_ms' from `esp-idf/espressif__arduino-esp32/libespressif__arduino-esp32.a(HWCDC.cpp.obj)'
D:/.espressif/tools/riscv32-esp-elf/esp-14.2.0_20241119/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/14.2.0/../../../../riscv32-esp-elf/bin/ld.exe: error: --enable-non-contiguous-regions discards section `.sdata.mux.5' from `esp-idf/joltwallet__littlefs/libjoltwallet__littlefs.a(esp_littlefs.c.obj)'
D:/.espressif/tools/riscv32-esp-elf/esp-14.2.0_20241119/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/14.2.0/../../../../riscv32-esp-elf/bin/ld.exe: error: --enable-non-contiguous-regions discards section `.sdata.__compound_literal.32' from `esp-idf/espressif__esp_lcd_st7701/libespressif__esp_lcd_st7701.a(esp_lcd_st7701_rgb.c.obj)'
D:/.espressif/tools/riscv32-esp-elf/esp-14.2.0_20241119/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/14.2.0/../../../../riscv32-esp-elf/bin/ld.exe: error: --enable-non-contiguous-regions discards section `.sdata.__compound_literal.31' from `esp-idf/espressif__esp_lcd_st7701/libespressif__esp_lcd_st7701.a(esp_lcd_st7701_rgb.c.obj)'
...
D:/.espressif/tools/riscv32-esp-elf/esp-14.2.0_20241119/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/14.2.0/../../../../riscv32-esp-elf/lib/rv32imafc_zicsr_zifencei/ilp32f/no-rtti\libstdc++.a(new_opvnt.o)'
D:/.espressif/tools/riscv32-esp-elf/esp-14.2.0_20241119/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/14.2.0/../../../../riscv32-esp-elf/lib/rv32imafc_zicsr_zifencei/ilp32f/no-rtti\libstdc++.a(eh_term_handler.o)'
D:/.espressif/tools/riscv32-esp-elf/esp-14.2.0_20241119/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/14.2.0/../../../../riscv32-esp-elf/bin/ld.exe: error: Total discarded sections size is 3586 bytes
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

 *  The terminal process "d:\.espressif\tools\ninja\1.12.1\ninja.EXE" terminated with exit code: 1.
I'm using ESP-IDF v5.5.1 under VSCode with Arduino as a Component v3.3.2. Build is for ESP32-P4.

horace99
Posts: 34
Joined: Mon Oct 14, 2024 10:38 am

Re: Serial.begin() leads to build errors

Postby horace99 » Sun Nov 16, 2025 10:25 am

can you post the program which gave the error messages?

Who is online

Users browsing this forum: Qwantbot and 4 guests