bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Bruno Haible <bruno@clisp.org>
To: bug-gnulib@gnu.org
Subject: gettime: Fix compilation error in C++ mode on Android
Date: Mon, 09 Jan 2023 11:10:09 +0100	[thread overview]
Message-ID: <2014450.M3retTD8dW@nimes> (raw)

In a testdir on Android, I see this compilation error:

clang++ -DNO_INLINE_GETPASS=1 -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-time-c++.o ../../gltests/test-time-c++.cc
In file included from ../../gltests/test-time-c++.cc:22:
../gllib/time.h:626:19: error: no member named 'timespec_get' in the global namespace
_GL_CXXALIAS_SYS (timespec_get, int, (struct timespec *ts, int base));
../gllib/sched.h:264:20: note: expanded from macro '_GL_CXXALIAS_SYS'
          return ::func;                                      \
In file included from ../../gltests/test-time-c++.cc:22:
../gllib/time.h:627:19: error: use of undeclared identifier 'timespec_get'; did you mean 'gnulib::timespec_get'?
_GL_CXXALIASWARN (timespec_get);
../gllib/time.h:626:19: note: 'gnulib::timespec_get' declared here
_GL_CXXALIAS_SYS (timespec_get, int, (struct timespec *ts, int base));
2 errors generated.
make[4]: *** [Makefile:23463: test-time-c++.o] Error 1

Here the problem is that timespec_get is only declared for a future API level:
/usr/include/time.h:int timespec_get(struct timespec* __ts, int __base) __INTRODUCED_IN(29);

This patch fixes the error, like in those cases where we use

2023-01-09  Bruno Haible  <bruno@clisp.org>

	gettime: Fix compilation error in C++ mode on Android.
	* m4/gettime.m4 (gl_CHECK_FUNC_TIMESPEC_GET): Also test whether
	timespec_get is declared.

diff --git a/m4/gettime.m4 b/m4/gettime.m4
index 06f32fe26c..7e353fcd00 100644
--- a/m4/gettime.m4
+++ b/m4/gettime.m4
@@ -1,4 +1,4 @@
-# gettime.m4 serial 12
+# gettime.m4 serial 13
 dnl Copyright (C) 2002, 2004-2006, 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,
@@ -26,17 +26,24 @@ AC_DEFUN([gl_CHECK_FUNC_TIMESPEC_GET],
   dnl We can't use AC_CHECK_FUNC here, because timespec_get() is defined as a
   dnl static inline function in <time.h> on MSVC 14.
-  AC_CACHE_CHECK([for timespec_get], [gl_cv_func_timespec_get],
-          [[#include <time.h>
-            struct timespec ts;
-          ]],
-          [[return timespec_get (&ts, 0);]])
-       ],
-       [gl_cv_func_timespec_get=yes],
-       [gl_cv_func_timespec_get=no])
-    ])
+  dnl But at the same time, we need to notice a missing declaration, like
+  dnl gl_CHECK_FUNCS_ANDROID does.
+  AC_CHECK_DECL([timespec_get], , , [[#include <time.h>]])
+  if test $ac_cv_have_decl_timespec_get = yes; then
+    AC_CACHE_CHECK([for timespec_get], [gl_cv_func_timespec_get],
+         [AC_LANG_PROGRAM(
+            [[#include <time.h>
+              struct timespec ts;
+            ]],
+            [[return timespec_get (&ts, 0);]])
+         ],
+         [gl_cv_func_timespec_get=yes],
+         [gl_cv_func_timespec_get=no])
+      ])
+  else
+    gl_cv_func_timespec_get=no
+  fi

                 reply	other threads:[~2023-01-09 10:10 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2014450.M3retTD8dW@nimes \
    --to=bruno@clisp.org \
    --cc=bug-gnulib@gnu.org \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).