Skip to content

[MinGW32] missing timespec_get() #830

@gvanem

Description

@gvanem

Trying to build for MinGW with the minimal features possible:

cmake -G "MinGW Makefiles" -DWITH_XML_BACKEND=0 -DWITH_SERIAL_BACKEND=0 -DWITH_USB_BACKEND=0 -DENABLE_IPV6=0 -DPYTHON_BINDINGS=0 -DWITH_NETWORK_BACKEND=0 ..

Yields:

F:\gv\dx-radio\libiio\tests\iio_common.c: In function 'get_time_us':
F:\gv\dx-radio\libiio\tests\iio_common.c:455:2: warning: implicit declaration of function 'timespec_get'
[-Wimplicit-function-declaration]
  455 |  timespec_get(&tp, TIME_UTC);
      |  ^~~~~~~~~~~~
F:\gv\dx-radio\libiio\tests\iio_common.c:455:20: error: 'TIME_UTC' undeclared (first use in this function)
  455 |  timespec_get(&tp, TIME_UTC);
      |                    ^~~~~~~~

My MinGW (TDM / gcc version 10.3.0) do have an inlined clock_gettime() in it's <pthread_time.h>
(which gets included in <time.h> for _POSIX_C_SOURCE > 2).
But inlined only for __MINGW64__! So I tried this patch:

--- a/tests/iio_common.c 2022-04-04 10:17:44
+++ b/tests/iio_common.c 2022-04-06 10:59:46
@@ -451,7 +451,9 @@
 {
        struct timespec tp;

-#ifdef _WIN32
+#if defined(__MINGW32__)
+       __pthread_clock_gettime(CLOCK_REALTIME, &tp);
+#elif defined(_WIN32)
        timespec_get(&tp, TIME_UTC);
 #else
        clock_gettime(CLOCK_REALTIME, &tp);

The above compiles and links for both -DBUILD_SHARED_LIBS=0 and -DBUILD_SHARED_LIBS=1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions