bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* gettime: Fix compilation error in C++ mode on Android
@ 2023-01-09 10:10 Bruno Haible
  0 siblings, 0 replies; only message in thread
From: Bruno Haible @ 2023-01-09 10:10 UTC (permalink / raw)
  To: bug-gnulib

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
gl_CHECK_FUNCS_ANDROID.


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],
-    [AC_LINK_IFELSE(
-       [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])
-    ])
+  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_LINK_IFELSE(
+         [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
 ])
 
 AC_DEFUN([gl_GETTIME_RES],





^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-01-09 10:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-09 10:10 gettime: Fix compilation error in C++ mode on Android Bruno Haible

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).