G. Branden Robinson wrote:
> > 1) Details about the OS: There are several variants of Solaris 11. Which
> >    one do you mean?
> 
> I'm using what's installed at gcc211.fsffrance.org.
> ...
> g++ (GCC) 5.5.0
> ...
> > 4) And, last not least, the tarball which you are attempting to compile?
> 
> 8.1MB file available at <https://paste.c-net.org/WanderLedge>.

Thanks. With these infos, I can reproduce it.

When I look at the preprocessor output of the failing compilation unit,
I see two definitions of 'rpl_getopt':

# lib/getopt-core.h:91
extern int 
          rpl_getopt 
                 (int ___argc, char *const *___argv, const char *__shortopts)
       noexcept (true) __attribute__ ((__nonnull__ (2, 3)));

# /usr/include/unistd.h:339
extern int 
           rpl_getopt
                 (int, char *const *, const char *);

But /usr/include/unistd.h is not meant to define rpl_getopt.
So, the problem is that <unistd.h> gets included too late.

This patch fixes it. Thanks for the report.


2025-01-16  Bruno Haible  <br...@clisp.org>

        getopt-posix: Fix compilation error in C++ mode (regression 2024-09-21).
        Reported by G. Branden Robinson <g.branden.robin...@gmail.com> in
        <https://lists.gnu.org/archive/html/bug-gnulib/2025-01/msg00135.html>.
        * lib/getopt-pfx-core.h: On several platforms, include <unistd.h> first.
        * modules/getopt-posix (Files): Add m4/musl.m4.
        (configure.ac): Invoke gl_MUSL_LIBC.

diff --git a/lib/getopt-pfx-core.h b/lib/getopt-pfx-core.h
index 391c7af8e7..7c5ea09468 100644
--- a/lib/getopt-pfx-core.h
+++ b/lib/getopt-pfx-core.h
@@ -37,6 +37,9 @@
 # if defined _AIX || defined __hpux || defined __sun || defined __QNX__
 #  include <stdio.h>
 # endif
+# if defined MUSL_LIBC || (defined __FreeBSD__ || defined __DragonFly__) || 
defined __NetBSD__ || defined __OpenBSD__ || (defined __APPLE__ && defined 
__MACH__) || defined _AIX || defined __sun || defined __minix || defined 
__HAIKU__
+#  include <unistd.h>
+# endif
 
 # ifndef __GETOPT_ID
 #  define __GETOPT_CONCAT(x, y) x ## y
diff --git a/modules/getopt-posix b/modules/getopt-posix
index 28ab405471..f27f5282e4 100644
--- a/modules/getopt-posix
+++ b/modules/getopt-posix
@@ -13,6 +13,7 @@ lib/getopt-pfx-ext.h
 lib/getopt_int.h
 m4/getopt.m4
 m4/sys_cdefs_h.m4
+m4/musl.m4
 
 Depends-on:
 unistd-h
@@ -35,6 +36,7 @@ AM_COND_IF([GL_COND_OBJ_GETOPT], [
   gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_UNISTD_H_GETOPT], [1])
 ])
 gl_UNISTD_MODULE_INDICATOR([getopt-posix])
+gl_MUSL_LIBC
 
 Makefile.am:
 BUILT_SOURCES += $(GETOPT_H) $(GETOPT_CDEFS_H)




  • Re: C++ problem bu... Bruno Haible via GNU roff typesetting system discussion
    • Re: C++ probl... G. Branden Robinson
      • Re: C++ p... Bruno Haible via GNU roff typesetting system discussion

Reply via email to