-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Description
Describe the bug
stdlib.h is not in the GCC search path when the C++ standard library is used.
To Reproduce
prj.conf:
CONFIG_NEWLIB_LIBC=y
CONFIG_CPLUSPLUS=y
main.cpp:
#include <zephyr.h>
#include <misc/printk.h>
#include <array>
void main(void)
{
std::array<int, 3> a{ 1, 2, 3 };
for (const auto x: a)
{
printk("x: %d", x);
}
}Steps to reproduce the behavior:
- mkdir build && cd build
- cmake -GNinja -DBOARD=arduino_zero ..
- ninja
- Build fails because of missing include, see console output below
Expected behavior
The example code above should compile.
Impact
I can not use the C++ standard library for my current project.
Screenshots or console output
> ninja
[15/101] Building CXX object CMakeFiles/app.dir/src/main.cpp.obj
FAILED: CMakeFiles/app.dir/src/main.cpp.obj
C:\Users\username\tools\gcc-arm-none-eabi-7-2018-q2-update-win32\bin\arm-none-eabi-g++.exe -DBUILD_VERSION=zephyr-v1.14.0 -DKERNEL -D_FORTIFY_SOURCE=2 -D__LINUX_ERRNO_EXTENSIONS__ -D__ZEPHYR__=1 -IC:/Users/username/zephyrproject/zephyr/kernel/include -IC:/Users/username/zephyrproject/zephyr/arch/arm/include -IC:/Users/username/zephyrproject/zephyr/include -IC:/Users/username/zephyrproject/zephyr/include/drivers -Izephyr/include/generated -IC:/Users/username/zephyrproject/zephyr/soc/arm/atmel_sam0/samd21 -IC:/Users/username/zephyrproject/zephyr/ext/hal/atmel/asf/sam0/include/samd21 -IC:/Users/username/zephyrproject/zephyr/ext/hal/cmsis/Include -isystem C:/Users/username/tools/gcc-arm-none-eabi-7-2018-q2-update-win32/arm-none-eabi/include -std=c++11 -Os -fcheck-new -Wno-register -fno-exceptions -fno-rtti -g -Wall -Wformat -Wformat-security -Wno-format-zero-length -imacros C:/Users/username/tmp/hello_world/build/zephyr/include/generated/autoconf.h -ffreestanding -Wno-main -fno-common -mthumb -mcpu=cortex-m0plus -fno-asynchronous-unwind-tables -fno-pie -fno-pic -fno-strict-overflow -Wno-unused-but-set-variable -fno-reorder-functions -fno-defer-pop -Werror=implicit-int -Wpointer-arith -ffunction-sections -fdata-sections -mabi=aapcs -march=armv6s-m -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
In file included from c:\users\username\tools\gcc-arm-none-eabi-7-2018-q2-update-win32\arm-none-eabi\include\c++\7.3.1\ext\string_conversions.h:41:0,
from c:\users\username\tools\gcc-arm-none-eabi-7-2018-q2-update-win32\arm-none-eabi\include\c++\7.3.1\bits\basic_string.h:6352,
from c:\users\username\tools\gcc-arm-none-eabi-7-2018-q2-update-win32\arm-none-eabi\include\c++\7.3.1\string:52,
from c:\users\username\tools\gcc-arm-none-eabi-7-2018-q2-update-win32\arm-none-eabi\include\c++\7.3.1\stdexcept:39,
from c:\users\username\tools\gcc-arm-none-eabi-7-2018-q2-update-win32\arm-none-eabi\include\c++\7.3.1\array:39,
from ../src/main.cpp:8:
c:\users\username\tools\gcc-arm-none-eabi-7-2018-q2-update-win32\arm-none-eabi\include\c++\7.3.1\cstdlib:75:15: fatal error: stdlib.h: No such file or directory
#include_next <stdlib.h>
^~~~~~~~~~
compilation terminated.
[28/101] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/printk.c.obj
ninja: build stopped: subcommand failed..Environment (please complete the following information):
- OS: Windows 10 1903
- Toolchain: GNU ARM Embedded 7-2018-q2-update
- Zephyr: v1.14.0
Additional context
This might be related to issue #15603. I tried the suggested workaround, but it does not help.
I tried several Zephyr versions:
- v1.14.1-rc1
- v1.14.99 (latest master, commit 1c6952c )
- v1.14.0-rc1
v1.14.0-rc1 works but in this version the shell is not C++ compatible yet, so there are other problems to work around.
I also tried the latest GNU ARM Embedded toolchain (8-2019-q3-update), but also no success here.
If you can point my in the right direction, I will happily provide a fix myself.