Trying to overload new and delete
void* operator new(std::size_t sz)
{
void* ptr = std::malloc(sz);
if (ptr)
{
return ptr;
}
else throw std::bad_alloc{};
}
void operator delete(void* ptr) noexcept
{
std::free(ptr); // Das macht der vordefinierte delete-Operator
}
gives linker errors for STM32 and Raspberry boards. However, for ESP32 it works.
How can I fix this?
Thanks
Richard
STM32-F303RE:
Quote:Linking it all together ...
# Coping cached core c131\core.a to _64\Release\core.a
rm-none-eabi-gcc\13.2.1-1.1/bin/arm-none-eabi-gcc" -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -Os -DNDEBUG -Wl,--defsym=LD_FLASH_OFFSET=0x0 -Wl,--defsym=LD_MAX_SIZE=524288 -Wl,--defsym=LD_MAX_DATA_SIZE=65536 -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=Reset_Handler -Wl,--unresolved-symbols=report-all -Wl,--warn-common tronics\hardware\stm32\2.9.0\variants\STM32F3xx\F303R(D-E)T/ldscript.ld" hardware\stm32\2.9.0\system/ldscript.ld" ics_Nucleo_64\Release/STM32-F303RE.ino.map" -Wl,--no-warn-rwx-segments -o o_64\Release/STM32-F303RE.ino.elf" leo_64\Release" -Wl,--start-group "STM32-F303RE.cpp.o" "SrcWrapper\syscalls.c.o" "SrcWrapper\HardwareTimer.cpp.o" "SrcWrapper\new.cpp.o" "SrcWrapper\HAL\stm32yyxx_hal.c.o" "SrcWrapper\HAL\stm32yyxx_hal_adc.c.o" "SrcWrapper\HAL\stm32yyxx_hal_adc_ex.c.o" "SrcWrapper\HAL\stm32yyxx_hal_can.c.o" "SrcWrapper\HAL\stm32yyxx_hal_cec.c.o" "SrcWrapper\HAL\stm32yyxx_hal_comp.c.o" "SrcWrapper\HAL\stm32yyxx_hal_comp_ex.c.o" "SrcWrapper\HAL\stm32yyxx_hal_cordic.c.o" "SrcWrapper\HAL\stm32yyxx_hal_cortex.c.o" "SrcWrapper\HAL\stm32yyxx_hal_crc.c.o" "SrcWrapper\HAL\stm32yyxx_hal_crc_ex.c.o" "SrcWrapper\HAL\stm32yyxx_hal_cryp.c.o" "SrcWrapper\HAL\stm32yyxx_hal_cryp_ex.c.o" "SrcWrapper\HAL\stm32yyxx_hal_dac.c.o" "SrcWrapper\HAL\stm32yyxx_hal_dac_ex.c.o" "SrcWrapper\HAL\stm32yyxx_hal_dcache.c.o" "SrcWrapper\HAL\stm32yyxx_hal_dcmi.c.o" "SrcWrapper\HAL\stm32yyxx_hal_dcmi_ex.c.o" "SrcWrapper\HAL\stm32yyxx_hal_dfsdm.c.o" "SrcWrapper\HAL\stm32yyxx_hal_dfsdm_ex.c.o" "SrcWrapper\HAL\stm32yyxx_hal_dma.c.o" "SrcWrapper\HAL\stm32yyxx_hal_dma2d.c.o" "SrcWrapper\HAL\stm32yyxx_hal_dma_ex.c.o" "SrcWrapper\HAL\stm32yyxx_hal_dsi.c.o" "SrcWrapper\HAL\stm32yyxx_hal_dts.c.o" "SrcWrapper\HAL\stm32yyxx_hal_eth.c.o" "SrcWrapper\HAL\stm32yyxx_hal_eth_ex.c.o" "SrcWrapper\HAL\stm32yyxx_hal_exti.c.o" "SrcWrapper\HAL\stm32yyxx_hal_fdcan.c.o" "SrcWrapper\HAL\stm32yyxx_hal_firewall.c.o" "SrcWrapper\HAL\stm32yyxx_hal_flash.c.o" "SrcWrapper\HAL\stm32yyxx_hal_flash_ex.c.o" "SrcWrapper\HAL\stm32yyxx_hal_flash_ramfunc.c.o" "SrcWrapper\HAL\stm32yyxx_hal_fmac.c.o" "SrcWrapper\HAL\stm32yyxx_hal_fmpi2c.c.o" "SrcWrapper\HAL\stm32yyxx_hal_fmpi2c_ex.c.o" "SrcWrapper\HAL\stm32yyxx_hal_fmpsmbus.c.o" "SrcWrapper\HAL\stm32yyxx_hal_fmpsmbus_ex.c.o" "SrcWrapper\HAL\stm32yyxx_hal_gfxmmu.c.o" "SrcWrapper\HAL\stm32yyxx_hal_gfxtim.c.o" "SrcWrapper\HAL\stm32yyxx_hal_gpio.c.o" "SrcWrapper\HAL\stm32yyxx_hal_gpio_ex.c.o" "SrcWrapper\HAL\stm32yyxx_hal_gpu2d.c.o" "SrcWrapper\HAL\stm32yyxx_hal_gtzc.c.o" "SrcWrapper\HAL\stm32yyxx_hal_hash.c.o" "SrcWrapper\HAL\stm32yyxx_hal_hash_ex.c.o" "SrcWrapper\HAL\stm32yyxx_hal_hcd.c.o" "SrcWrapper\HAL\stm32yyxx_hal_hrtim.c.o" "SrcWrapper\HAL\stm32yyxx_hal_hsem.c.o" "SrcWrapper\HAL\stm32yyxx_hal_i2c.c.o" "SrcWrapper\HAL\stm32yyxx_hal_i2c_ex.c.o" "SrcWrapper\HAL\stm32yyxx_hal_i2s.c.o" "SrcWrapper\HAL\stm32yyxx_hal_i2s_ex.c.o" "SrcWrapper\HAL\stm32yyxx_hal_i3c.c.o" "SrcWrapper\HAL\stm32yyxx_hal_icache.c.o" "SrcWrapper\HAL\stm32yyxx_hal_ipcc.c.o" "SrcWrapper\HAL\stm32yyxx_hal_irda.c.o" "SrcWrapper\HAL\stm32yyxx_hal_iwdg.c.o" "SrcWrapper\HAL\stm32yyxx_hal_jpeg.c.o" "SrcWrapper\HAL\stm32yyxx_hal_lcd.c.o" "SrcWrapper\HAL\stm32yyxx_hal_lptim.c.o" "SrcWrapper\HAL\stm32yyxx_hal_ltdc.c.o" "SrcWrapper\HAL\stm32yyxx_hal_ltdc_ex.c.o" "SrcWrapper\HAL\stm32yyxx_hal_mdf.c.o" "SrcWrapper\HAL\stm32yyxx_hal_mdios.c.o" "SrcWrapper\HAL\stm32yyxx_hal_mdma.c.o" "SrcWrapper\HAL\stm32yyxx_hal_mmc.c.o" "SrcWrapper\HAL\stm32yyxx_hal_mmc_ex.c.o" "SrcWrapper\HAL\stm32yyxx_hal_nand.c.o" "SrcWrapper\HAL\stm32yyxx_hal_nor.c.o" "SrcWrapper\HAL\stm32yyxx_hal_opamp.c.o" "SrcWrapper\HAL\stm32yyxx_hal_opamp_ex.c.o" "SrcWrapper\HAL\stm32yyxx_hal_ospi.c.o" "SrcWrapper\HAL\stm32yyxx_hal_otfdec.c.o" "SrcWrapper\HAL\stm32yyxx_hal_pccard.c.o" "SrcWrapper\HAL\stm32yyxx_hal_pcd.c.o" "SrcWrapper\HAL\stm32yyxx_hal_pcd_ex.c.o" "SrcWrapper\HAL\stm32yyxx_hal_pka.c.o" "SrcWrapper\HAL\stm32yyxx_hal_pssi.c.o" "SrcWrapper\HAL\stm32yyxx_hal_pwr.c.o" "SrcWrapper\HAL\stm32yyxx_hal_pwr_ex.c.o" "SrcWrapper\HAL\stm32yyxx_hal_qspi.c.o" "SrcWrapper\HAL\stm32yyxx_hal_ramcfg.c.o" "SrcWrapper\HAL\stm32yyxx_hal_ramecc.c.o" "SrcWrapper\HAL\stm32yyxx_hal_rcc.c.o" "SrcWrapper\HAL\stm32yyxx_hal_rcc_ex.c.o" "SrcWrapper\HAL\stm32yyxx_hal_rng.c.o" "SrcWrapper\HAL\stm32yyxx_hal_rng_ex.c.o" "SrcWrapper\HAL\stm32yyxx_hal_rtc.c.o" "SrcWrapper\HAL\stm32yyxx_hal_rtc_ex.c.o" "SrcWrapper\HAL\stm32yyxx_hal_sai.c.o" "SrcWrapper\HAL\stm32yyxx_hal_sai_ex.c.o" "SrcWrapper\HAL\stm32yyxx_hal_sd.c.o" "SrcWrapper\HAL\stm32yyxx_hal_sdadc.c.o" "SrcWrapper\HAL\stm32yyxx_hal_sdio.c.o" "SrcWrapper\HAL\stm32yyxx_hal_sdram.c.o" "SrcWrapper\HAL\stm32yyxx_hal_sd_ex.c.o" "SrcWrapper\HAL\stm32yyxx_hal_smartcard.c.o" "SrcWrapper\HAL\stm32yyxx_hal_smartcard_ex.c.o" "SrcWrapper\HAL\stm32yyxx_hal_smbus.c.o" "SrcWrapper\HAL\stm32yyxx_hal_smbus_ex.c.o" "SrcWrapper\HAL\stm32yyxx_hal_spdifrx.c.o" "SrcWrapper\HAL\stm32yyxx_hal_spi.c.o" "SrcWrapper\HAL\stm32yyxx_hal_spi_ex.c.o" "SrcWrapper\HAL\stm32yyxx_hal_sram.c.o" "SrcWrapper\HAL\stm32yyxx_hal_subghz.c.o" "SrcWrapper\HAL\stm32yyxx_hal_swpmi.c.o" "SrcWrapper\HAL\stm32yyxx_hal_tim.c.o" "SrcWrapper\HAL\stm32yyxx_hal_tim_ex.c.o" "SrcWrapper\HAL\stm32yyxx_hal_tsc.c.o" "SrcWrapper\HAL\stm32yyxx_hal_uart.c.o" "SrcWrapper\HAL\stm32yyxx_hal_uart_ex.c.o" "SrcWrapper\HAL\stm32yyxx_hal_usart.c.o" "SrcWrapper\HAL\stm32yyxx_hal_usart_ex.c.o" "SrcWrapper\HAL\stm32yyxx_hal_wwdg.c.o" "SrcWrapper\HAL\stm32yyxx_hal_xspi.c.o" "SrcWrapper\LL\stm32yyxx_ll_adc.c.o" "SrcWrapper\LL\stm32yyxx_ll_bdma.c.o" "SrcWrapper\LL\stm32yyxx_ll_comp.c.o" "SrcWrapper\LL\stm32yyxx_ll_cordic.c.o" "SrcWrapper\LL\stm32yyxx_ll_crc.c.o" "SrcWrapper\LL\stm32yyxx_ll_crs.c.o" "SrcWrapper\LL\stm32yyxx_ll_dac.c.o" "SrcWrapper\LL\stm32yyxx_ll_delayblock.c.o" "SrcWrapper\LL\stm32yyxx_ll_dlyb.c.o" "SrcWrapper\LL\stm32yyxx_ll_dma.c.o" "SrcWrapper\LL\stm32yyxx_ll_dma2d.c.o" "SrcWrapper\LL\stm32yyxx_ll_exti.c.o" "SrcWrapper\LL\stm32yyxx_ll_fmac.c.o" "SrcWrapper\LL\stm32yyxx_ll_fmc.c.o" "SrcWrapper\LL\stm32yyxx_ll_fmpi2c.c.o" "SrcWrapper\LL\stm32yyxx_ll_fsmc.c.o" "SrcWrapper\LL\stm32yyxx_ll_gpio.c.o" "SrcWrapper\LL\stm32yyxx_ll_hrtim.c.o" "SrcWrapper\LL\stm32yyxx_ll_i2c.c.o" "SrcWrapper\LL\stm32yyxx_ll_i3c.c.o" "SrcWrapper\LL\stm32yyxx_ll_icache.c.o" "SrcWrapper\LL\stm32yyxx_ll_lpgpio.c.o" "SrcWrapper\LL\stm32yyxx_ll_lptim.c.o" "SrcWrapper\LL\stm32yyxx_ll_lpuart.c.o" "SrcWrapper\LL\stm32yyxx_ll_mdma.c.o" "SrcWrapper\LL\stm32yyxx_ll_opamp.c.o" "SrcWrapper\LL\stm32yyxx_ll_pka.c.o" "SrcWrapper\LL\stm32yyxx_ll_pwr.c.o" "SrcWrapper\LL\stm32yyxx_ll_rcc.c.o" "SrcWrapper\LL\stm32yyxx_ll_rng.c.o" "SrcWrapper\LL\stm32yyxx_ll_rtc.c.o" "SrcWrapper\LL\stm32yyxx_ll_sdmmc.c.o" "SrcWrapper\LL\stm32yyxx_ll_spi.c.o" "SrcWrapper\LL\stm32yyxx_ll_swpmi.c.o" "SrcWrapper\LL\stm32yyxx_ll_tim.c.o" "SrcWrapper\LL\stm32yyxx_ll_ucpd.c.o" "SrcWrapper\LL\stm32yyxx_ll_usart.c.o" "SrcWrapper\LL\stm32yyxx_ll_usb.c.o" "SrcWrapper\LL\stm32yyxx_ll_utils.c.o" "SrcWrapper\stm32\bootloader.c.o" "SrcWrapper\stm32\clock.c.o" "SrcWrapper\stm32\core_callback.c.o" "SrcWrapper\stm32\dwt.c.o" "SrcWrapper\stm32\hw_config.c.o" "SrcWrapper\stm32\otp.c.o" "SrcWrapper\stm32\pinmap.c.o" "SrcWrapper\stm32\PortNames.c.o" "SrcWrapper\stm32\stm32_def.c.o" "SrcWrapper\stm32\system_stm32yyxx.c.o" "SrcWrapper\stm32\timer.c.o" "SrcWrapper\stm32\uart.c.o" "SrcWrapper\stm32\analog.cpp.o" "SrcWrapper\stm32\interrupt.cpp.o" ac131\variant\generic_clock.c.o" ac131\variant\PeripheralPins.c.o" ac131\variant\variant_generic.cpp.o" ac131\variant\variant_NUCLEO_F303RE.cpp.o" o_64\Release\core.a" -lc -Wl,--end-group -lm -lgcc -lstdc++
ld.exe: SrcWrapper\\new.cpp.o: in function operator new(unsigned int)
new.cpp*: (.text._Znwj+0x0): multiple definition of operator new(unsigned int); STM32-F303RE.cpp.o:STM32-F303RE.cpp:(.text._Znwj+0x0): first defined here
ld.exe: SrcWrapper\\new.cpp.o: in function operator delete(void*)
new.cpp*: (.text._ZdlPv+0x0): multiple definition of operator delete(void*); STM32-F303RE.cpp.o:STM32-F303RE.cpp:(.text._ZdlPv+0x0): first defined here
collect2.exe*: error: ld returned 1 exit status
Error linking for board Nucleo-64 (STMicroelectronics_Nucleo_64)
Build failed for project 'STM32-F303RE'
Raspberry Pico 2
Quote:Linking it all together ...
# recipe.hooks.linking.prelink.1.pattern
ase-3a57aed-1/python3" -I ls/simplesub.py" --input /rp2350/memmap_default.ld" --out mmap_default.ld" --sub __FLASH_LENGTH__ 4186112 --sub __EEPROM_START__ 272621568 --sub __FS_START__ 272621568 --sub __FS_END__ 272621568 --sub __RAM_LENGTH__ 512k --sub __PSRAM_LENGTH__ 0x000000
# recipe.hooks.linking.prelink.2.pattern
6f/bin/arm-none-eabi-gcc" -Werror=return-type -Wno-psabi -DUSBD_PID=0x000f -DUSBD_VID=0x2e8a -DUSBD_MAX_POWER_MA=250 "-DUSB_MANUFACTURER=\"Raspberry Pi\"" "-DUSB_PRODUCT=\"Pico 2\"" -DLWIP_IPV6=0 -DLWIP_IPV4=1 -DLWIP_IGMP=1 -DLWIP_CHECKSUM_CTRL_PER_NETIF=1 "-DARDUINO_VARIANT=\"rpipico2\"" -DPICO_FLASH_SIZE_BYTES=4194304 b/rp2350/platform_def.txt" -mcpu=cortex-m33 -mthumb -march=armv8-m.main+fp+dsp -mfloat-abi=softfp -mcmse -ffunction-sections -fdata-sections -fexceptions -Os -u _printf_float -u _scanf_float -c t2/rp2350/none.S" ico-sdk/src/rp2350/hardware_regs/include/" ico-sdk/src/common/pico_binary_info/include" -o ot2.o"
# Coping cached core d87b\core.a to e.a
6f/bin/arm-none-eabi-g++" -Werror=return-type -Wno-psabi -DUSBD_PID=0x000f -DUSBD_VID=0x2e8a -DUSBD_MAX_POWER_MA=250 "-DUSB_MANUFACTURER=\"Raspberry Pi\"" "-DUSB_PRODUCT=\"Pico 2\"" -DLWIP_IPV6=0 -DLWIP_IPV4=1 -DLWIP_IGMP=1 -DLWIP_CHECKSUM_CTRL_PER_NETIF=1 "-DARDUINO_VARIANT=\"rpipico2\"" -DPICO_FLASH_SIZE_BYTES=4194304 b/rp2350/platform_def.txt" -mcpu=cortex-m33 -mthumb -march=armv8-m.main+fp+dsp -mfloat-abi=softfp -mcmse -ffunction-sections -fdata-sections -fexceptions -Os -u _printf_float -u _scanf_float b/rp2350/platform_wrap.txt" b/core_wrap.txt" -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--undefined=runtime_init_install_ram_vector_table -Wl,--undefined=__pre_init_runtime_init_clocks -Wl,--undefined=__pre_init_runtime_init_bootrom_reset -Wl,--undefined=__pre_init_runtime_init_early_resets -Wl,--undefined=__pre_init_runtime_init_usb_power_down -Wl,--undefined=__pre_init_runtime_init_clocks -Wl,--undefined=__pre_init_runtime_init_post_clock_resets -Wl,--undefined=__pre_init_runtime_init_spin_locks_reset -Wl,--undefined=__pre_init_runtime_init_boot_locks_reset -Wl,--undefined=__pre_init_runtime_init_bootrom_locking_enable -Wl,--undefined=__pre_init_runtime_init_mutex -Wl,--undefined=__pre_init_runtime_init_default_alarm_pool -Wl,--undefined=__pre_init_first_per_core_initializer -Wl,--undefined=__pre_init_runtime_init_per_core_bootrom_reset -Wl,--undefined=__pre_init_runtime_init_per_core_h3_irq_registers -Wl,--undefined=__pre_init_runtime_init_per_core_irq_priorities ico2\Debug/memmap_default.ld" \Debug/Raspi-RP2350.ino.map" -o spi-RP2350.ino.elf" -Wl,--no-warn-rwx-segments -Wl,--start-group "Raspi-RP2350.cpp.o" "VM_DBG\VM_DBG.cpp.o" "VM_DBG\VM_mem_check_sam.cpp.o" re.a" ot2.o" /rp2350/ota.o" /rp2350/libpico.a" /rp2350/libipv4.a" /rp2350/libbearssl.a" -lm -lc -lstdc++-exc -lc -Wl,--end-group
ld.exe: 4.4.1\lib\rp2350\libpico.a(new_delete.cpp.o): in function _Znwj
new_delete.cpp*:15: d \cpp-2015.boo\Beispiele\Embedded-Cpp\exception-basics.h first defined here
ld.exe: 4.4.1\lib\rp2350\libpico.a(new_delete.cpp.o): in function _ZdlPv
new_delete.cpp*:22: d \cpp-2015.boo\Beispiele\Embedded-Cpp\exception-basics.h first defined here
collect2.exe*: error: ld returned 1 exit status
Error linking for board Raspberry Pi Pico 2 (rp2040_rpipico2)
Debug build failed for project 'Raspi-RP2350'