etl: Placement new does not compile with Zephyr

Hello all,

I’d like to use ETL on a Zephyr based project, but I’m having issue using containers. The following snippet compiles just fine on my pc

void foo() {
    etl::vector<int, 10> v;
    v.push_back(1);
}

but fails with the following error when compiling with zephyr’s g++ (arm-zephyr-eabi-g++ (Zephyr SDK 0.16.0) 12.2.0):

etl/include/etl/memory.h: In instantiation of 'void etl::create_copy_at(T*, T&&) [with T = int]':
etl/include/etl/vector.h:1064:26:   required from 'void etl::ivector<T>::create_back(rvalue_reference) [with T = int; rvalue_reference = int&&]'
etl/include/etl/vector.h:451:18:   required from 'void etl::ivector<T>::push_back(rvalue_reference) [with T = int; rvalue_reference = int&&]'
src/main.cpp:90:20:   required from here
etl/include/etl/memory.h:1820:5: error: no matching function for call to 'operator new(sizetype, int*&)'
 1820 |     ::new (p) T(etl::move(value));
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<built-in>: note: candidate: 'void* operator new(unsigned int)'
<built-in>: note:   candidate expects 1 argument, 2 provided
<built-in>: note: candidate: 'void* operator new(unsigned int, std::align_val_t)'
<built-in>: note:   no known conversion for argument 2 from 'int*' to 'std::align_val_t'

The build command is the following (redacted):

/opt/zephyr-sdk-0.16.0/arm-zephyr-eabi/bin/arm-zephyr-eabi-g++ -DETL_NO_STL -DHSE_VALUE=8000000 -DKERNEL -DSTM32F070xB -DUSE_FULL_LL_DRIVER -DUSE_HAL_DRIVER -D__PROGRAM_START -D__ZEPHYR__=1 -Isrc -Isrc/include -I/home/gabbla/zephyrproject/zephyr/include -Ibuild/zephyr/include/generated -I/home/gabbla/zephyrproject/zephyr/soc/arm/st_stm32/stm32f0 -I/home/gabbla/zephyrproject/zephyr/lib/posix/getopt/. -I/home/gabbla/zephyrproject/zephyr/drivers -I/home/gabbla/zephyrproject/zephyr/soc/arm/st_stm32/common -I/home/gabbla/zephyrproject/modules/hal/cmsis/CMSIS/Core/Include -I/home/gabbla/zephyrproject/modules/hal/stm32/stm32cube/stm32f0xx/soc -I/home/gabbla/zephyrproject/modules/hal/stm32/stm32cube/stm32f0xx/drivers/include -I/home/gabbla/zephyrproject/modules/hal/stm32/stm32cube/stm32f0xx/drivers/include/Legacy -I/home/gabbla/zephyrproject/modules/hal/stm32/stm32cube/common_ll/include -isystem /home/gabbla/zephyrproject/zephyr/lib/libc/minimal/include -isystem /home/gabbla/zephyrproject/zephyr/lib/cpp/minimal/include -isystem /opt/zephyr-sdk-0.16.0/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/include -isystem /opt/zephyr-sdk-0.16.0/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/include-fixed -isystem /modules/etl/include -fno-strict-aliasing -Os -fcheck-new -std=c++20 -Wno-register -Wno-volatile -fno-exceptions -fno-rtti -imacros /build/zephyr/include/generated/autoconf.h -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m0 -mthumb -mabi=aapcs --sysroot=/opt/zephyr-sdk-0.16.0/arm-zephyr-eabi/arm-zephyr-eabi -imacros /home/gabbla/zephyrproject/zephyr/include/zephyr/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-main -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -fno-asynchronous-unwind-tables -fno-reorder-functions --param=min-pagesize=0 -fno-defer-pop -fmacro-prefix-map==CMAKE_SOURCE_DIR -fmacro-prefix-map=/home/gabbla/zephyrproject/zephyr=ZEPHYR_BASE -fmacro-prefix-map=/home/gabbla/zephyrproject=WEST_TOPDIR -ffunction-sections -fdata-sections -D_POSIX_THREADS -nostdinc -nostdinc++ -MD -MT CMakeFiles/app.dir/src/main.cpp.obj -MF CMakeFiles/app.dir/src/main.cpp.obj.d -o CMakeFiles/app.dir/src/main.cpp.obj -c src/main.cpp

I’m pretty sure I’m missing something on the configuration side. Any suggestion?

Best regards, Gab

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 15 (10 by maintainers)

Most upvoted comments

Hi, @gabbla So I’m testing ETL with Zephyr and came across this issue. To use the standard new from Zephyr you need to add the following to proj.conf: CONFIG_LIB_CPLUSPLUS=y CONFIG_NEWLIB_LIBC=y

This should enable the standard library.

Can you try defining ETL_USING_STD_NEW as 0 or 1 in your project to see if either one works?