Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MinGW32] missing timespec_get() #830

Closed
gvanem opened this issue Apr 6, 2022 · 4 comments · Fixed by #835
Closed

[MinGW32] missing timespec_get() #830

gvanem opened this issue Apr 6, 2022 · 4 comments · Fixed by #835

Comments

@gvanem
Copy link

gvanem commented Apr 6, 2022

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.

@pcercuei
Copy link
Contributor

pcercuei commented Apr 6, 2022

Since you say that your MinGW does have clock_gettime(), why not:

#if defined(_WIN32) && !defined(__MINGW32__)
    timespec_get(&tp, TIME_UTC);
#else
    clock_gettime(CLOCK_REALTIME, &tp);
#endif

@gvanem
Copy link
Author

gvanem commented Apr 6, 2022

But it is inlined only for __MINGW64__ / x64; excluding 32-bit targets.
But this issue is really not important for me. I've abandoned MinGW some years ago due to such messy issues.
So feel free to close or fix at own will.

@gvanem
Copy link
Author

gvanem commented Apr 6, 2022

Besides your CMakeLists.txt is really not for x86 on MINGW (-m32) at all.
How does this hellish Cmake system choose to build 32-bit targets?

@pcercuei
Copy link
Contributor

pcercuei commented Apr 6, 2022

Besides your CMakeLists.txt is really not for x86 on MINGW (-m32) at all. How does this hellish Cmake system choose to build 32-bit targets?

Easy - just use a 32-bit MinGW toolchain :)

pcercuei added a commit that referenced this issue Apr 6, 2022
MinGW 32-bit does not have timespec_get(). Strangely, the 64-bit version
does have it. But both have clock_gettime(), so only use timespec_get()
when building under Visual Studio.

Fixes #830.

Signed-off-by: Paul Cercueil <[email protected]>
@rgetz rgetz closed this as completed in #835 Apr 6, 2022
rgetz pushed a commit that referenced this issue Apr 6, 2022
MinGW 32-bit does not have timespec_get(). Strangely, the 64-bit version
does have it. But both have clock_gettime(), so only use timespec_get()
when building under Visual Studio.

Fixes #830.

Signed-off-by: Paul Cercueil <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants