[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
timespec_get: Fix compilation error with MSVC 14
From: |
Bruno Haible |
Subject: |
timespec_get: Fix compilation error with MSVC 14 |
Date: |
Sun, 04 Sep 2022 17:15:28 +0200 |
A testdir fails to compile on MSVC 14, because of this error:
source='../../gllib/timespec_get.c' object='timespec_get.obj' libtool=no \
DEPDIR=.deps depmode=msvc7 /bin/sh ../../build-aux/depcomp \
/home/bruno/msvc/compile cl -nologo -DHAVE_CONFIG_H -DEXEEXT=\".exe\"
-DEXEEXT=\".exe\" -DNO_XMALLOC -DEXEEXT=\".exe\" -I. -I../../gllib -I..
-DGNULIB_STRICT_CHECKING=1 -D_WIN32_WINNT=_WIN32_WINNT_WIN7
-I/usr/local/msvc64/include -MD -c -o timespec_get.obj `cygpath -w
'../../gllib/timespec_get.c'`
timespec_get.c
C:\cygwin64\home\bruno\testdir-all\gllib\timespec_get.c(26): error C2084:
function 'int timespec_get(timespec *const ,const int)' already has a body
C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\time.h(539):
note: see previous definition of 'timespec_get'
make[4]: *** [Makefile:10692: timespec_get.obj] Error 2
The cause is that this platform's <time.h> contains a 'static inline'
definition of timespec_get, and our AC_CHECK_FUNCS_ONCE([timespec_get])
invocation does not see it:
checking for timespec_get... no
This patch fixes it, by changing the configuration to produce
checking for timespec_get... yes
2022-09-04 Bruno Haible <bruno@clisp.org>
timespec_get: Fix compilation error with MSVC 14.
* m4/gettime.m4 (gl_CHECK_FUNC_TIMESPEC_GET): New macro.
(gl_GETTIME): Use it instead of AC_CHECK_FUNCS_ONCE.
* m4/timespec_get.m4 (gl_FUNC_TIMESPEC_GET): Likewise.
diff --git a/m4/gettime.m4 b/m4/gettime.m4
index f0aeb4d0e4..c3e0713b57 100644
--- a/m4/gettime.m4
+++ b/m4/gettime.m4
@@ -1,4 +1,4 @@
-# gettime.m4 serial 11
+# gettime.m4 serial 12
dnl Copyright (C) 2002, 2004-2006, 2009-2022 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -9,7 +9,34 @@ AC_DEFUN([gl_GETTIME],
dnl Prerequisites of lib/gettime.c.
AC_REQUIRE([gl_CLOCK_TIME])
AC_REQUIRE([gl_TIMESPEC])
- AC_CHECK_FUNCS_ONCE([timespec_get])
+
+ AC_REQUIRE([gl_CHECK_FUNC_TIMESPEC_GET])
+ if test $gl_cv_func_timespec_get = yes; then
+ AC_DEFINE([HAVE_TIMESPEC_GET], [1],
+ [Define if you have the timespec_get function.])
+ fi
+])
+
+dnl Tests whether the function timespec_get exists.
+dnl Sets gl_cv_func_timespec_get.
+AC_DEFUN([gl_CHECK_FUNC_TIMESPEC_GET],
+[
+ dnl Persuade OpenBSD <time.h> to declare timespec_get().
+ AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
+
+ 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])
+ ])
])
AC_DEFUN([gl_GETTIME_RES],
diff --git a/m4/timespec_get.m4 b/m4/timespec_get.m4
index cc5ce299de..acea56d626 100644
--- a/m4/timespec_get.m4
+++ b/m4/timespec_get.m4
@@ -1,4 +1,4 @@
-# timespec_get.m4 serial 2
+# timespec_get.m4 serial 3
dnl Copyright (C) 2021-2022 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -11,8 +11,8 @@ AC_DEFUN([gl_FUNC_TIMESPEC_GET],
dnl Persuade OpenBSD <time.h> to declare timespec_get().
AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
- AC_CHECK_FUNCS_ONCE([timespec_get])
- if test $ac_cv_func_timespec_get != yes; then
+ AC_REQUIRE([gl_CHECK_FUNC_TIMESPEC_GET])
+ if test $gl_cv_func_timespec_get != yes; then
HAVE_TIMESPEC_GET=0
fi
])
- timespec_get: Fix compilation error with MSVC 14,
Bruno Haible <=