trns1997 commented on PR #17968:
URL: https://github.com/apache/nuttx/pull/17968#issuecomment-3765121575
@simbit18 I dug into this further and I believe I’ve identified the
underlying reason for the failure.
In tools/Config.mk, when building with the C++ toolchain, we always add
NuttX’s C++ compatibility headers to the include path:
```
# The default C/C++ search path
ARCHINCLUDES += ${INCSYSDIR_PREFIX}$(TOPDIR)$(DELIM)include
ifeq ($(CONFIG_LIBCXX),y)
ARCHXXINCLUDES += ${INCSYSDIR_PREFIX}$(TOPDIR)$(DELIM)include$(DELIM)libcxx
else ifeq ($(CONFIG_UCLIBCXX),y)
ARCHXXINCLUDES +=
${INCSYSDIR_PREFIX}$(TOPDIR)$(DELIM)include$(DELIM)uClibc++
else
ARCHXXINCLUDES += ${INCSYSDIR_PREFIX}$(TOPDIR)$(DELIM)include$(DELIM)cxx
ifeq ($(CONFIG_ETL),y)
ARCHXXINCLUDES += ${INCSYSDIR_PREFIX}$(TOPDIR)$(DELIM)include$(DELIM)etl
endif
endif
```
So for the “plain” CXX case, `include/cxx` is implicitly part of the system
include path.
This directory contains the NuttX C/C++ compatibility headers that are meant
to sit in front of the toolchain’s libc headers.
In the CMake build, however, `include/cxx` is currently not added to the C++
include directories. As a result, the toolchain’s `<stdlib.h>` gets pulled in
first via `<cstdlib>`, which then conflicts with NuttX’s own `stdlib.h`
(`div_t`, `ldiv_t`, `lldiv_t`, etc.), exactly as seen in the error log.
To harmonize Makefile and CMake behavior, I think we need explicitly add
`include/cxx` when C++ is enabled in CMake, e.g. in
`arch/arm/src/cmake/gcc.cmake` :
```
if(CONFIG_HAVE_CXX)
list(APPEND CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES
${CMAKE_SOURCE_DIR}/include/cxx)
endif()
```
This makes the CMake build consistent with what the Makefile-based build
already does today and resolves the conflicting type definitions.
That said, I do have one open question for CXX users; When building with the
external C++ toolchain, is it expected that NuttX’s `include/cxx` headers are
always used?
My understanding is that these headers are required to maintain NuttX C++
compatibility (wrapping or redefining parts of the standard library to coexist
with NuttX’s libc), so including them even with a full C++ toolchain seems
intentional and correct.
But if the long-term expectation is that a “pure” toolchain C++ build should
not rely on `include/cxx`, then the Makefile behavior itself might need
revisiting.
What do you think? I would also like @leducp @xiaoxiang781216 input on this
:)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]