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-sched-h-c++.cc' object='test-sched-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-sched-h-c++.o
test-sched-h-c++.cc
"./../gllib/sched.h", line 618: Error: sched_yield is not defined.
1 Error(s) detected.
gmake[4]: *** [Makefile:30132: test-sched-h-c++.o] Error 2
The problem is a recursive include chain:
gllib/sched.h
-> /usr/include/sched.h
-> gllib/sys/types.h
-> /usr/include/sys/types.h
-> gllib/sys/select.h
-> gllib/signal.h
-> gllib/pthread.h
-> /usr/include/pthread.h
-> gllib/sched.h
and the best place to cut this chain is in gllib/signal.h.
Given that
- Solaris 9 and newer declare pthread_sigmask() in <signal.h>,
- Support for C++ on Solaris 10 is more important than support for
Solaris 8 and older,
I'm committing this fix:
2026-05-10 Bruno Haible <[email protected]>
signal.h: Fix compilation error on Solaris 10 in C++ mode.
* lib/signal.in.h: On Solaris in C++ mode, don't include <pthread.h>.
The include <pthread.h> is only needed for Solaris versions < 9.
diff --git a/lib/signal.in.h b/lib/signal.in.h
index e4fa3fbaf2..9e140ca5e8 100644
--- a/lib/signal.in.h
+++ b/lib/signal.in.h
@@ -74,12 +74,13 @@
/* Mac OS X 10.3, FreeBSD < 8.0, OpenBSD < 5.1, Solaris 2.6, Android,
OS/2 kLIBC declare pthread_sigmask in <pthread.h>, not in <signal.h>.
- But avoid namespace pollution on glibc systems.*/
+ But avoid namespace pollution on glibc systems. */
#if (@GNULIB_PTHREAD_SIGMASK@ || defined GNULIB_POSIXCHECK) \
&& ((defined __APPLE__ && defined __MACH__) \
|| (defined __FreeBSD__ && __FreeBSD__ < 8) \
|| (defined __OpenBSD__ && OpenBSD < 201205) \
- || defined __sun || defined __ANDROID__ \
+ || (defined __sun && !defined __cplusplus) \
+ || defined __ANDROID__ \
|| defined __KLIBC__) \
&& ! defined __GLIBC__
# include <pthread.h>