Building a testdir of all of Gnulib on Solaris 10 with Oracle Studio 12.6
and no optimization
  CC="cc -D_STDC_C99="; CXX="CC"; export CC CXX
in a non-VPATH build, I see a link error:

source='test-sys_wait-h-c++.cc' object='test-sys_wait-h-c++.o' libtool=no \
DEPDIR=.deps depmode=none /bin/bash ../build-aux/depcomp \
CC -DHAVE_CONFIG_H -DEXEEXT=\"\" -DEXEEXT=\"\" -I. -I..  
-DGNULIB_STRICT_CHECKING=1 -DIN_GNULIB_TESTS=1 -I. -I. -I.. -I./.. -I../gllib 
-I./../gllib -D_REENTRANT -Wno-error -Wno-error -g -c -o test-sys_wait-h-c++.o 
test-sys_wait-h-c++.cc
"./../gllib/sys/wait.h", line 645: Error: waitpid is not defined.
1 Error(s) detected.
gmake[4]: *** [Makefile:30132: test-sys_wait-h-c++.o] Error 2

This patch fixes it. It uses the same technique as the 'math-h' module.


2026-05-10  Bruno Haible  <[email protected]>

        sys_wait-h: Fix compilation error on Solaris 10 in C++ mode.
        * lib/sys_wait.in.h (_GL_INCLUDING_SYS_WAIT_H): New macro, to avoid
        recursive include problems.
        * modules/sys_wait-h (Makefile.am): Substitute
        INCLUDE_NEXT_AS_FIRST_DIRECTIVE, NEXT_AS_FIRST_DIRECTIVE_SYS_WAIT_H.

diff --git a/lib/sys_wait.in.h b/lib/sys_wait.in.h
index 884c63d84f..8d4145d782 100644
--- a/lib/sys_wait.in.h
+++ b/lib/sys_wait.in.h
@@ -22,9 +22,23 @@
 #endif
 @PRAGMA_COLUMNS@
 
+#if defined _GL_INCLUDING_SYS_WAIT_H
+/* Special invocation convention:
+   - On Solaris 10 we have a sequence of nested includes
+     <sys/wait.h> -> <stdlib.h> -> <sys/wait.h>
+     In this situation, the functions are not yet declared, therefore we cannot
+     provide the C++ aliases.  */
+
+#@INCLUDE_NEXT_AS_FIRST_DIRECTIVE@ @NEXT_AS_FIRST_DIRECTIVE_SYS_WAIT_H@
+
+#else
+/* Normal invocation convention.  */
+
 /* The include_next requires a split double-inclusion guard.  */
 #if !(defined _WIN32 && ! defined __CYGWIN__)
+# define _GL_INCLUDING_SYS_WAIT_H
 # @INCLUDE_NEXT@ @NEXT_SYS_WAIT_H@
+# undef _GL_INCLUDING_SYS_WAIT_H
 #endif
 
 #ifndef _@GUARD_PREFIX@_SYS_WAIT_H
@@ -132,4 +146,5 @@ _GL_WARN_ON_USE (waitpid, "waitpid is unportable - "
 
 
 #endif /* _@GUARD_PREFIX@_SYS_WAIT_H */
+#endif /* _GL_INCLUDING_SYS_WAIT_H */
 #endif /* _@GUARD_PREFIX@_SYS_WAIT_H */
diff --git a/modules/sys_wait-h b/modules/sys_wait-h
index 455cf961fb..d995b1aedb 100644
--- a/modules/sys_wait-h
+++ b/modules/sys_wait-h
@@ -26,9 +26,11 @@ sys/wait.h: sys_wait.in.h $(top_builddir)/config.status 
$(CXXDEFS_H) $(WARN_ON_U
        $(AM_V_GEN)$(MKDIR_P) '%reldir%/sys'
        $(AM_V_at)$(SED_HEADER_STDOUT) \
              -e 's|@''GUARD_PREFIX''@|${gl_include_guard_prefix}|g' \
+             -e 
's|@''INCLUDE_NEXT_AS_FIRST_DIRECTIVE''@|$(INCLUDE_NEXT_AS_FIRST_DIRECTIVE)|g' \
              -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
              -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
              -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
+             -e 
's|@''NEXT_AS_FIRST_DIRECTIVE_SYS_WAIT_H''@|$(NEXT_AS_FIRST_DIRECTIVE_SYS_WAIT_H)|g'
 \
              -e 's|@''NEXT_SYS_WAIT_H''@|$(NEXT_SYS_WAIT_H)|g' \
              -e 's/@''GNULIB_WAITPID''@/$(GNULIB_WAITPID)/g' \
              -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \




Reply via email to