Skip to content

[BUG] include/cxx is unconditionally added for C++ builds and should be guarded by LIBCXXMINI / LIBMINIABI #18088

@trns1997

Description

@trns1997

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Arch: allIssues that apply to all architecturesArea: Build systemOS: LinuxIssues related to Linux (building system, etc)Type: BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions