In a testdir on Android, I get this compilation error: clang++ -ferror-limit=0 -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/data/data/com.termux/files/home/local/include -Wall -Wno-error -g -O2 -c -o test-stdlib-c++.o ../../gltests/test-stdlib-c++.cc
In file included from ../../gltests/test-stdlib-c++.cc:22: In file included from ../gllib/stdlib.h:36: In file included from /data/data/com.termux/files/usr/include/c++/v1/stdlib.h:97: In file included from /data/data/com.termux/files/usr/include/stdlib.h:276: In file included from /data/data/com.termux/files/usr/include/android/legacy_stdlib_inlines.h:91: ../gllib/stdlib.h:1002:19: error: no member named 'getsubopt' in the global namespace; did you mean 'getopt'? _GL_CXXALIAS_SYS (getsubopt, int, ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~ In file included from ../../gltests/test-stdlib-c++.cc:22: In file included from ../gllib/stdlib.h:36: In file included from /data/data/com.termux/files/usr/include/c++/v1/stdlib.h:97: In file included from /data/data/com.termux/files/usr/include/stdlib.h:276: In file included from /data/data/com.termux/files/usr/include/android/legacy_stdlib_inlines.h:91: ../gllib/stdlib.h:1002:1: error: cannot initialize return object of type 'gnulib::_gl_getsubopt_wrapper::type' (aka 'int (*)(char **, char *const *, char **)') with an lvalue of type 'int (int, char *const *, const char *)': type mismatch at 1st parameter ('char **' vs 'int') _GL_CXXALIAS_SYS (getsubopt, int, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from ../../gltests/test-stdlib-c++.cc:22: In file included from ../gllib/stdlib.h:36: In file included from /data/data/com.termux/files/usr/include/c++/v1/stdlib.h:97: In file included from /data/data/com.termux/files/usr/include/stdlib.h:276: In file included from /data/data/com.termux/files/usr/include/android/legacy_stdlib_inlines.h:91: ../gllib/stdlib.h:1004:19: error: use of undeclared identifier 'getsubopt'; did you mean 'gnulib::getsubopt'? _GL_CXXALIASWARN (getsubopt); ^ The cause is that the function getsubopt is declared only for a later API level of Android: /usr/include/stdlib.h:int getsubopt(char** __option, char* const* __tokens, char** __value_ptr) __INTRODUCED_IN(26); This patch fixes the error. 2023-01-09 Bruno Haible <br...@clisp.org> getsubopt: Fix compilation error in C++ mode on Android. * m4/getsubopt.m4 (gl_FUNC_GETSUBOPT): Use gl_CHECK_FUNCS_ANDROID instead of AC_CHECK_FUNCS_ONCE. diff --git a/m4/getsubopt.m4 b/m4/getsubopt.m4 index 0753b1f64c..a528ec7143 100644 --- a/m4/getsubopt.m4 +++ b/m4/getsubopt.m4 @@ -1,4 +1,4 @@ -# getsubopt.m4 serial 5 +# getsubopt.m4 serial 6 dnl Copyright (C) 2004, 2007, 2009-2023 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -10,7 +10,10 @@ AC_DEFUN([gl_FUNC_GETSUBOPT], AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) - AC_CHECK_FUNCS_ONCE([getsubopt]) + gl_CHECK_FUNCS_ANDROID([getsubopt], + [[#include <stdlib.h> + #include <unistd.h> + ]]) if test $ac_cv_func_getsubopt = no; then HAVE_GETSUBOPT=0 fi