This is an automated email from the ASF dual-hosted git repository. lupyuen pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit 55a7d4d2df0b95cda489afa3ad5c48d0ca3d4e5d Author: Arjav Patel <[email protected]> AuthorDate: Sat May 23 09:52:17 2026 +0000 apps/system/microros: define __NuttX__ in cross-compile toolchain flags. Add -D__NuttX__ to CMAKE_C_FLAGS_INIT and CMAKE_CXX_FLAGS_INIT in toolchain.cmake.in so that all cross-compiled micro-ROS packages see the NuttX target macro. Without this, rcutils/src/process.c follows the __linux__ branch and references program_invocation_name, a glibc-only extension absent from the NuttX C library. Pair with 0002-rcutils-process-nuttx-compat.patch which additionally guards the linux branch with !defined(__NuttX__), ensuring the embedded fallback path is taken on NuttX even if the host compiler defines any linux-flavoured macros. Signed-off-by: Arjav Patel <[email protected]> --- system/microros/micro_ros_lib/toolchain.cmake.in | 4 ++-- .../patches/0002-rcutils-process-nuttx-compat.patch | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/system/microros/micro_ros_lib/toolchain.cmake.in b/system/microros/micro_ros_lib/toolchain.cmake.in index dbdc290e2..8d3aabe3c 100644 --- a/system/microros/micro_ros_lib/toolchain.cmake.in +++ b/system/microros/micro_ros_lib/toolchain.cmake.in @@ -9,8 +9,8 @@ set(PLATFORM_NAME "nuttx") set(CMAKE_C_COMPILER @CMAKE_C_COMPILER@) set(CMAKE_CXX_COMPILER @CMAKE_CXX_COMPILER@) -set(CMAKE_C_FLAGS_INIT "-std=c11 @ARCH_C_FLAGS@ -D'__attribute__(x)='" CACHE STRING "" FORCE) -set(CMAKE_CXX_FLAGS_INIT "-std=c++14 @ARCH_CPP_FLAGS@ -fno-rtti -D'__attribute__(x)='" CACHE STRING "" FORCE) +set(CMAKE_C_FLAGS_INIT "-std=c11 @ARCH_C_FLAGS@ -D__NuttX__ -D'__attribute__(x)='" CACHE STRING "" FORCE) +set(CMAKE_CXX_FLAGS_INIT "-std=c++14 @ARCH_CPP_FLAGS@ -fno-rtti -D__NuttX__ -D'__attribute__(x)='" CACHE STRING "" FORCE) set(NUTTX_TOPDIR @NUTTX_TOPDIR@) set(NUTTX_APPDIR @NUTTX_APPDIR@) diff --git a/system/microros/patches/0002-rcutils-process-nuttx-compat.patch b/system/microros/patches/0002-rcutils-process-nuttx-compat.patch new file mode 100644 index 000000000..ca8b6c56a --- /dev/null +++ b/system/microros/patches/0002-rcutils-process-nuttx-compat.patch @@ -0,0 +1,20 @@ +From: micro-ROS NuttX Port <[email protected]> +Subject: [PATCH] rcutils: skip program_invocation_name on NuttX + +When cross-compiling for NuttX on a Linux host the compiler still +defines __linux__, causing rcutils_get_executable_name() to reference +program_invocation_name which is a glibc extension absent from the +NuttX C library. Guard the Linux branch with !defined(__NuttX__) so +the "embedded OS" fallback (empty string) is taken instead. + +--- a/rcutils/src/process.c ++++ b/rcutils/src/process.c +@@ -61,7 +61,7 @@ int rcutils_get_pid() + #if defined __APPLE__ || defined __FreeBSD__ || (defined __ANDROID__ && __ANDROID_API__ >= 21) + const char * appname = getprogname(); + #elif defined __GNUC__ && !defined(__QNXNTO__) && !defined(__OHOS__) +- #if defined __linux__ || defined __linux || defined __gnu_linux__ || defined linux ++ #if (defined __linux__ || defined __linux || defined __gnu_linux__ || defined linux) && !defined(__NuttX__) + const char * appname = program_invocation_name; + #else + // Some embedded OS compile with __GNUC__ but are not quite conformant with GNU-specific extensions.
