Skip to content

Unable to use C++ Standard Library #15603

@mrfuchs

Description

@mrfuchs

Describe the bug
C++ Standard Library cannot be used with Zephyr 1.14.0. It used to work with 1.14-rc1.

To Reproduce
prj.conf: CONFIG_CPLUSPLUS=y

main.cpp:

#include <zephyr.h>
#include <vector>

int main()
{
  std::vector<int> v;

  v.push_back(10); 
  
  for (int x : v) 
    printk("x: %d", x); 

  return 0;
}

Command line: D:\zephyr-test>cmake -GNinja -Bbuild -H. -DBOARD=stm32f4_disco && ninja -C build

Output:

Zephyr version: 1.14.0
-- Found PythonInterp: C:/Users/user/AppData/Local/Programs/Python/Python37/
python.exe (found suitable version "3.7.0", minimum required is "3.4")
-- Selected BOARD stm32f4_disco
-- Loading D:/test/zephyr-v1.14.0/boards/arm/stm32f4_disco/stm32f4_disco.dts as
base
-- Overlaying D:/test/zephyr-v1.14.0/dts/common/common.dts
Parsing Kconfig tree in D:/test/zephyr-v1.14.0/Kconfig
Loading D:/test/zephyr-v1.14.0/boards/arm/stm32f4_disco/stm32f4_disco_defconfig
as base
Merging D:/zephyr-test/prj.conf
Configuration written to 'D:/zephyr-test/build/zephyr/.config'
-- Cache files will be written to: C:\Users\user\AppData\Local/.cache/zephyr

-- The C compiler identification is GNU 8.2.1
-- The CXX compiler identification is GNU 8.2.1
-- The ASM compiler identification is GNU
-- Found assembler: C:/Program Files (x86)/GNU Tools Arm Embedded/8 2018-q4-majo
r/bin/arm-none-eabi-gcc.exe
-- Performing Test toolchain_is_ok
-- Performing Test toolchain_is_ok - Success
-- Configuring done
-- Generating done
-- Build files have been written to: D:/zephyr-test/build
ninja: Entering directory `build'
...
../src/main.cpp:2:10: fatal error: vector: No such file or directory
 #include <vector>
          ^~~~~~~~
compilation terminated.
[13/121] Building C object zephyr/arch...__arm__core__cortex_m.dir/prep_c.c.obj
ninja: build stopped: subcommand failed.

Expected behavior
It compiles, as with 1.14-rc1:

D:\zephyr-test>cmake -GNinja -Bbuild -H. -DBOARD=stm32f4_disco && ninja -C build

Zephyr version: 1.14.0
-- Found PythonInterp: C:/Users/user/AppData/Local/Programs/Python/Python37/
python.exe (found suitable version "3.7.0", minimum required is "3.4")
-- Selected BOARD stm32f4_disco
-- Loading D:/test/zephyr-1.14.0-rc1/boards/arm/stm32f4_disco/stm32f4_disco.dts
as base
-- Overlaying D:/test/zephyr-1.14.0-rc1/dts/common/common.dts
Parsing Kconfig tree in D:/test/zephyr-1.14.0-rc1/Kconfig
Loading D:/test/zephyr-1.14.0-rc1/boards/arm/stm32f4_disco/stm32f4_disco_defconf
ig as base
Merging D:/zephyr-test/prj.conf
Configuration written to 'D:/zephyr-test/build/zephyr/.config'
-- Cache files will be written to: C:\Users\user\AppData\Local/.cache/zephyr

-- The C compiler identification is GNU 8.2.1
-- The CXX compiler identification is GNU 8.2.1
-- The ASM compiler identification is GNU
-- Found assembler: C:/Program Files (x86)/GNU Tools Arm Embedded/8 2018-q4-majo
r/bin/arm-none-eabi-gcc.exe
-- Performing Test toolchain_is_ok
-- Performing Test toolchain_is_ok - Success
Including module(s):
-- Configuring done
-- Generating done
-- Build files have been written to: D:/zephyr-test/build
ninja: Entering directory `build'
[116/121] Linking CXX executable zephyr\zephyr_prebuilt.elf
Memory region         Used Size  Region Size  %age Used
           FLASH:       13592 B         1 MB      1.30%
            SRAM:        4348 B       192 KB      2.21%
        IDT_LIST:         120 B         2 KB      5.86%
[121/121] Linking CXX executable zephyr\zephyr.elf

Impact
Cannot update to Zephyr 1.14.0 for current development project.

Environment (please complete the following information):

  • OS: Windows
  • Toolchain: GNU ARM Embedded
  • Version used: Zephyr 1.14.0

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions