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

Windows: _FPCLASS_SNAN’ undeclared on mingw32 #2302

Closed
Alexander-Barth opened this issue Apr 25, 2022 · 3 comments
Closed

Windows: _FPCLASS_SNAN’ undeclared on mingw32 #2302

Alexander-Barth opened this issue Apr 25, 2022 · 3 comments

Comments

@Alexander-Barth
Copy link
Contributor

Alexander-Barth commented Apr 25, 2022

I am hitting a small issue when compiling NetCDF 4.8.1 on Windows with mingw32. In essence _FPCLASS_SNAN is not defined on mingw32 but isnan is defined like on Linux/Unix. Instead testing _WIN32 the patch checks for _MSC_VER.

  • the version of the software with which you are encountering an issue

NetCDF 4.8.1

  • environmental information (i.e. Operating System, compiler info, java version, python version, etc.)

OS: Linux x86_64 with cross-compiliation to x86_64-w64-mingw32 (target)
Compiler: x86_64-w64-mingw32-gcc (GCC) 4.8.5

  • a description of the issue with the steps needed to reproduce it

I configure and compile NetCDF to the following option:

./configure 
    --build=${MACHTYPE} \                                                                                                                                             
    --host=${target} \                                                                                                                                                
    --enable-shared \                                                                                                                                                 
    --disable-static \                                                                                                                                                
    --disable-dap-remote-tests \    
   --disable-utilities                                                                                                                                  
make LDFLAGS="-lhdf5-0 -lhdf5_hl-0 -lcurl-4 -lz -no-undefined -Wl,--export-all-symbols"                                                                                                                             

The compilation fails with:

[09:16:52] libtool: compile:  cc -DHAVE_CONFIG_H -I. -I.. -I../include -I../include -I../oc2 -D_LARGEFILE_SOURCE -I../libsrc4 -I../libdap4 -I/workspace/destdir/include -std=c99 -fno-strict-aliasing -MT libnczarr_la-zcvt.lo -MD -MP -MF .deps/libnczarr_la-zcvt.Tpo -c zcvt.c  -DDLL_EXPORT -DPIC -o .libs/libnczarr_la-zcvt.o
[09:16:52] libtool: compile:  cc -DHAVE_CONFIG_H -I. -I.. -I../include -I../include -I../oc2 -D_LARGEFILE_SOURCE -I../libsrc4 -I../libdap4 -I/workspace/destdir/include -std=c99 -fno-strict-aliasing -MT libnczarr_la-zxcache.lo -MD -MP -MF .deps/libnczarr_la-zxcache.Tpo -c zxcache.c  -DDLL_EXPORT -DPIC -o .libs/libnczarr_la-zxcache.o
[09:16:52] libtool: compile:  cc -DHAVE_CONFIG_H -I. -I.. -I../include -I../include -I../oc2 -D_LARGEFILE_SOURCE -I../libsrc4 -I../libdap4 -I/workspace/destdir/include -std=c99 -fno-strict-aliasing -MT libnczarr_la-zcreate.lo -MD -MP -MF .deps/libnczarr_la-zcreate.Tpo -c zcreate.c  -DDLL_EXPORT -DPIC -o .libs/libnczarr_la-zcreate.o
[09:16:52] zcvt.c: In function ‘NCZ_stringconvert’:
[09:16:52] zcvt.c:351:3: warning: implicit declaration of function ‘_fpclass’ [-Wimplicit-function-declaration]
[09:16:52]    switch (_fpclass(d)) {
[09:16:52]    ^
[09:16:52] zcvt.c:352:8: error: ‘_FPCLASS_SNAN’ undeclared (first use in this function)
[09:16:52]    case _FPCLASS_SNAN: case _FPCLASS_QNAN:
[09:16:52]         ^
[09:16:52] zcvt.c:352:8: note: each undeclared identifier is reported only once for each function it appears in
[09:16:52] zcvt.c:352:28: error: ‘_FPCLASS_QNAN’ undeclared (first use in this function)
[09:16:52]    case _FPCLASS_SNAN: case _FPCLASS_QNAN:
[09:16:52]                             ^
[09:16:52] zcvt.c:354:8: error: ‘_FPCLASS_NINF’ undeclared (first use in this function)
[09:16:52]    case _FPCLASS_NINF:
[09:16:52]         ^
[09:16:52] zcvt.c:356:8: error: ‘_FPCLASS_PINF’ undeclared (first use in this function)
[09:16:52]    case _FPCLASS_PINF:
[09:16:52]         ^
[09:16:52] make[2]: *** [Makefile:676: libnczarr_la-zcvt.lo] Error 1
[09:16:52] make[2]: *** Waiting for unfinished jobs....


[09:16:52] mv -f .deps/libnczarr_la-zdim.Tpo .deps/libnczarr_la-zdim.Plo
[09:16:52] mv -f .deps/libnczarr_la-zcreate.Tpo .deps/libnczarr_la-zcreate.Plo
[09:16:52] mv -f .deps/libnczarr_la-zchunking.Tpo .deps/libnczarr_la-zchunking.Plo
[09:16:52] mv -f .deps/libnczarr_la-zarr.Tpo .deps/libnczarr_la-zarr.Plo
[09:16:52] mv -f .deps/libnczarr_la-zclose.Tpo .deps/libnczarr_la-zclose.Plo
[09:16:52] mv -f .deps/libnczarr_la-zxcache.Tpo .deps/libnczarr_la-zxcache.Plo
[09:16:52] mv -f .deps/libnczarr_la-zattr.Tpo .deps/libnczarr_la-zattr.Plo
[09:16:52] make[2]: Leaving directory '/workspace/srcdir/netcdf-c-4.8.1/libnczarr'
[09:16:52] make[1]: *** [Makefile:729: all-recursive] Error 1
[09:16:52] make[1]: Leaving directory '/workspace/srcdir/netcdf-c-4.8.1'
[09:16:52] make: *** [Makefile:574: all] Error 2
[09:16:52]  ---> make LDFLAGS="${LDFLAGS_MAKE}" -j${nproc}
[09:16:52]  ---> make LDFLAGS="${LDFLAGS_MAKE}" -j${nproc}
[09:16:52] Previous command exited with 2
[09:16:52] Child Process exited, exit code 2
ERROR: LoadError: Build for NetCDF on x86_64-w64-mingw32 did not complete successfully

This patch solves this issue:

From b7766b6cf56c4792c29d8573c190fb84c8119b59 Mon Sep 17 00:00:00 2001
From: Alexander Barth <[email protected]>
Date: Wed, 2 Mar 2022 15:37:16 +0100
Subject: [PATCH 3/3] _fpclass not defined on mingw

---
 libnczarr/zcvt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libnczarr/zcvt.c b/libnczarr/zcvt.c
index 374eda5b..28f5d223 100644
--- a/libnczarr/zcvt.c
+++ b/libnczarr/zcvt.c
@@ -347,7 +347,7 @@ NCZ_stringconvert(nc_type typeid, size_t len, void* data0, NCjson** jdatap)
 	  	    d = (double)(*((float*)src));
 		else
 	  	    d = *((double*)src);
-#ifdef _WIN32
+#ifdef _MSC_VER
 		switch (_fpclass(d)) {
 		case _FPCLASS_SNAN: case _FPCLASS_QNAN:
 		     special = "Nan"; break;
-- 
2.25.1

I just made a PR for this issue.

Reference:
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/fpclass-fpclassf?view=msvc-170

@WardF
Copy link
Member

WardF commented Apr 25, 2022

Thank you, a PR would be great, although I am curious as to why I am not observing this on my own mingw32 installation. Thanks!

@Alexander-Barth
Copy link
Contributor Author

Yes, I make a PR here: #2305

@Alexander-Barth
Copy link
Contributor Author

Thanks for merging the PR.

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

No branches or pull requests

2 participants