Building a gnulib testdir on AIX 7.3, I see this compilation error:

/opt/freeware/bin/g++ -DHAVE_CONFIG_H -DEXEEXT=\"\" -DEXEEXT=\"\" -I. 
-I../../gltests -I..  -DGNULIB_STRICT_CHECKING=1 -DIN_GNULIB_TESTS=1 -I. 
-I../../gltests -I.. -I../../gltests/.. -I../gllib -I../../gltests/../gllib 
-I/home/haible/prefix32/include -Wall -D_THREAD_SAFE -Wno-error -Wno-error -g 
-O2 -MT test-strings-h-c++.o -MD -MP -MF $depbase.Tpo -c -o 
test-strings-h-c++.o ../../gltests/test-strings-h-c++.cc &&\
mv -f $depbase.Tpo $depbase.Po
In file included from /usr/include/strings.h:128,
                 from ../gllib/strings.h:34,
                 from ../../gltests/test-strings-h-c++.cc:22:
../gllib/string.h:1823:1: error: template with C linkage
 1823 | template <typename T> T strnul (T);
      | ^~~~~~~~
/usr/include/strings.h:43:1: note: 'extern "C"' linkage started here
   43 | extern "C" {
      | ^~~~~~~~~~
../gllib/string.h:1824:1: error: template specialization with C linkage
 1824 | template <> inline const char *strnul<const char *> (const char *s)
      | ^~~~~~~~
/usr/include/strings.h:43:1: note: 'extern "C"' linkage started here
   43 | extern "C" {
      | ^~~~~~~~~~
../gllib/string.h:1826:1: error: template specialization with C linkage
 1826 | template <> inline       char *strnul<      char *> (      char *s)
      | ^~~~~~~~
/usr/include/strings.h:43:1: note: 'extern "C"' linkage started here
   43 | extern "C" {
      | ^~~~~~~~~~
gmake[4]: *** [Makefile:30129: test-strings-h-c++.o] Error 1

The problem is that the system's /usr/include/strings.h does a
  #include <string.h>
inside an 'extern "C" { ... }' block. For the system's <string.h> this
works fine, but Gnulib's <string.h> override contains a few template
declarations, which want to be consumed in "C++" mode, not in "C" mode.

The common convention is that all .h files must be included *outside*
of extern "C" blocks.

Therefore, this is the correct fix:


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

        strings-h: Fix compilation error on AIX in C++ mode.
        * lib/strings.in.h: On AIX in C++ mode, before including the system's
        <strings.h> file, include <string.h>.

diff --git a/lib/strings.in.h b/lib/strings.in.h
index fd7cd2df67..68152e83bd 100644
--- a/lib/strings.in.h
+++ b/lib/strings.in.h
@@ -30,6 +30,11 @@
 
 /* The include_next requires a split double-inclusion guard.  */
 #if @HAVE_STRINGS_H@
+/* AIX 7.3 has a bug: In C++ mode, <string.h> must be included before
+   <strings.h>.  */
+# if defined __cplusplus && defined _AIX
+#  include <string.h>
+# endif
 # @INCLUDE_NEXT@ @NEXT_STRINGS_H@
 #endif
 




  • strnul and AIX C++ Bruno Haible via Gnulib discussion list

Reply via email to