Build excludes paths to standard C++ headers when using GNUARMEMB toolchain variant #36823
Labels
area: C++
bug
The issue is a bug, or the PR is fixing a bug
priority: medium
Medium impact/importance bug
Milestone
Describe the bug
Using the
gnuarmemb
toolchain variant to build a trivial application fails if any source file in the application includes a standard C++ header.To Reproduce
Steps to reproduce the behavior:
main.cc
(ormain.cpp
if you prefer):Expected behavior
Build should complete without error.
Impact
Unable to generate any firmware images for target hardware.
Logs and console output
The compiler invocation command that fails is shown below. Newlines have been added for readability, and some path information has been redacted.
Environment (please complete the following information):
Additional context
The reason that this failure is occurring for this toolchain variant is that the Zephyr build system adds the
-nostdinc
flag to the build. (zephyr/CMakeLists.txt) This is done with the (obviously wrong) assumption that the build system has discovered all of the implicit system include paths and added them as explicit system include paths. (zephyr/cmake/compiler/gcc/compiler_flags.cmake).Zephyr's assumption that it is safe to add
-nostdinc
to the build is wrong. This is because the locations of the standard C++ headers are never discovered. The discovery routine only looks for the paths to the C headersinclude/stddef.h
andinclude-fixed/limits.h
. (zephyr/cmake/compiler/gcc/target.cmake) No attempt is made to look for any C++ headers, even ifCONFIG_CPLUSPLUS
is enabled. Without the paths to the standard C++ headers, the build fails.Note that this problem doesn't occur with the
host-gcc
toolchain variant because in that circumstance the-nostdinc
flag is not added to the build.Proposed Fix(es)
The easiest fix would be to exclude the
-nostdinc
flag from the build when CONFIG_CPLUSPLUS is set.The harder fix would be to properly discover all of the system include paths for the C++ compiler when CONFIG_CPLUSPLUS is set and explicitly add those paths to the build. This approach is challenging because the technique used for discovering the location of the C headers does not work for discovering the location of C++ headers (at least with GCC/G++). Passing the
-print-file-name
flag tog++
does not print full path to the specified header.The best alternative option this developer could discover would be to use the following compiler invocation (borrowed from StackOverflow here ):
and to parse the resulting output.
EDIT:
Related to #36644.
The text was updated successfully, but these errors were encountered: