-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Description / Steps to reproduce the issue
When building NuttX with C++ enabled, the Makefile logic in tools/Config.mk unconditionally adds include/cxx to the system include path whenever neither CONFIG_LIBCXX nor CONFIG_UCLIBCXX is selected:
# 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
This means that include/cxx is implicitly used even when building with an external C++ toolchain (CONFIG_LIBCXXTOOLCHAIN=y).
However, include/cxx does not provide a full C++ standard library implementation. Instead, it provides NuttX-specific C++ ABI compatibility headers (similar in role to libcxxabi, not libcxx). As discussed, these headers should only be used when the mini C++ ABI is explicitly enabled see discussion in PR #17968.
Using include/cxx with a full external C++ toolchain can cause conflicts between the toolchain’s standard headers and NuttX’s libc headers (e.g. conflicting definitions of div_t, ldiv_t, lldiv_t via <cstdlib> / <stdlib.h>). In practice, the Makefile behavior is overly permissive and works but is not entirely correct.
The correct behavior should be:
include/cxx is only added to the include path when the mini C++ ABI is explicitly enabled (LIBCXXMINI / LIBMINIABI) with a start in PR #17990
When using CONFIG_LIBCXXTOOLCHAIN, the toolchain-provided C++ headers should be used without implicitly injecting include/cxx
This is a broader correctness issue that affects both Makefile and CMake builds. While CMake currently exposes the problem more clearly (addressed in PR #17968), the root cause is the Makefile include logic itself.
On which OS does this issue occur?
[OS: Linux]
What is the version of your OS?
Ubuntu 24.04
NuttX Version
master
Issue Architecture
[Arch: all]
Issue Area
[Area: Build System]
Host information
No response
Verification
- I have verified before submitting the report.