Unidata / netcdf-c

Official GitHub repository for netCDF-C libraries and utilities.
BSD 3-Clause "New" or "Revised" License
515 stars 262 forks source link

building GDAL fails with netcdf 4.9.3-rc1 #3028

Closed tbussmann closed 1 month ago

tbussmann commented 1 month ago

OS: macOS 14 with XCode CLT 15.3

Building netcdf-c 4.9.3-rc1 (with -DNETCDF_ENABLE_HDF5=OFF -DNETCDF_BUILD_UTILITIES=OFF) works successfully, one failed test, see #3027.

Building GDAL 3.8.5 against that fials with error: use of undeclared identifier '_FillValue'. Doing the same against netcdf 4.9.2 builds successfully.

Build log ``` [ 49%] Building CXX object frmts/netcdf/CMakeFiles/gdal_netCDF.dir/netcdfdataset.cpp.o /Users/admin/Documents/PostgresApp/src-17/gdal-3.8.5/frmts/netcdf/netcdfdataset.cpp:466:42: error: use of undeclared identifier '_FillValue' int status = nc_inq_att(cdfid, nZId, _FillValue, &atttype, &attlen); ^ /Users/admin/Documents/PostgresApp/src-17/gdal-3.8.5/frmts/netcdf/netcdfdataset.cpp:469:26: error: use of undeclared identifier '_FillValue' pszNoValueName = _FillValue; ^ /Users/admin/Documents/PostgresApp/src-17/gdal-3.8.5/frmts/netcdf/netcdfdataset.cpp:1220:13: error: use of undeclared identifier '_FillValue' _FillValue, "coordinates", nullptr}; ^ /Users/admin/Documents/PostgresApp/src-17/gdal-3.8.5/frmts/netcdf/netcdfdataset.cpp:1538:56: error: use of undeclared identifier '_FillValue' status = nc_put_att_schar(cdfid, nZId, _FillValue, nc_datatype, ^ /Users/admin/Documents/PostgresApp/src-17/gdal-3.8.5/frmts/netcdf/netcdfdataset.cpp:1545:56: error: use of undeclared identifier '_FillValue' status = nc_put_att_uchar(cdfid, nZId, _FillValue, nc_datatype, ^ /Users/admin/Documents/PostgresApp/src-17/gdal-3.8.5/frmts/netcdf/netcdfdataset.cpp:1552:52: error: use of undeclared identifier '_FillValue' status = nc_put_att_short(cdfid, nZId, _FillValue, nc_datatype, 1, ^ /Users/admin/Documents/PostgresApp/src-17/gdal-3.8.5/frmts/netcdf/netcdfdataset.cpp:1558:50: error: use of undeclared identifier '_FillValue' status = nc_put_att_int(cdfid, nZId, _FillValue, nc_datatype, 1, ^ /Users/admin/Documents/PostgresApp/src-17/gdal-3.8.5/frmts/netcdf/netcdfdataset.cpp:1564:52: error: use of undeclared identifier '_FillValue' status = nc_put_att_float(cdfid, nZId, _FillValue, nc_datatype, 1, ^ /Users/admin/Documents/PostgresApp/src-17/gdal-3.8.5/frmts/netcdf/netcdfdataset.cpp:1574:53: error: use of undeclared identifier '_FillValue' status = nc_put_att_ushort(cdfid, nZId, _FillValue, nc_datatype, 1, ^ /Users/admin/Documents/PostgresApp/src-17/gdal-3.8.5/frmts/netcdf/netcdfdataset.cpp:1582:51: error: use of undeclared identifier '_FillValue' status = nc_put_att_uint(cdfid, nZId, _FillValue, nc_datatype, 1, ^ /Users/admin/Documents/PostgresApp/src-17/gdal-3.8.5/frmts/netcdf/netcdfdataset.cpp:1588:53: error: use of undeclared identifier '_FillValue' status = nc_put_att_double(cdfid, nZId, _FillValue, nc_datatype, 1, ^ /Users/admin/Documents/PostgresApp/src-17/gdal-3.8.5/frmts/netcdf/netcdfdataset.cpp:1667:55: error: use of undeclared identifier '_FillValue' status = nc_put_att_longlong(cdfid, nZId, _FillValue, nc_datatype, ^ /Users/admin/Documents/PostgresApp/src-17/gdal-3.8.5/frmts/netcdf/netcdfdataset.cpp:1674:53: error: use of undeclared identifier '_FillValue' status = nc_put_att_double(cdfid, nZId, _FillValue, nc_datatype, 1, ^ /Users/admin/Documents/PostgresApp/src-17/gdal-3.8.5/frmts/netcdf/netcdfdataset.cpp:1753:56: error: use of undeclared identifier '_FillValue' status = nc_put_att_ulonglong(cdfid, nZId, _FillValue, nc_datatype, ^ /Users/admin/Documents/PostgresApp/src-17/gdal-3.8.5/frmts/netcdf/netcdfdataset.cpp:1760:53: error: use of undeclared identifier '_FillValue' status = nc_put_att_double(cdfid, nZId, _FillValue, nc_datatype, 1, ^ /Users/admin/Documents/PostgresApp/src-17/gdal-3.8.5/frmts/netcdf/netcdfdataset.cpp:10084:9: error: use of undeclared identifier '_FillValue' _FillValue, "coordinates", nullptr}; ^ ```
tbussmann commented 1 month ago

this seems to be the same issue as in #3017

WardF commented 1 month ago

I suspect this is the result of refactoring_FillValue to NC_FillValue, as discussed in #2858 and changed in #2911. I will highlight this in the release notes, and I'll submit a PR to GDAL if I can confirm this is the case.

WardF commented 1 month ago

Looking at GDAL, it appears (at least in main) that this change has been accounted for, looking at netcdfdataset.h. Comparing against netcdfdataset.h in GDAL v3.8.5, it doesn't appear to accommodate this change. It feels like the path forward here is to upgrade to a newer version of GDAL, or revert to an holder version of netCDF. I'm open to a discussion about other alternatives, if these are non-starters.

tbussmann commented 1 month ago

Thanks for explaining the context! The fix from GDAL master was already backported to the 3.9 branch. The 3.8 branch seems not longer maintained according to their maintenance policy. But with the information provided patching 3.8 seems to be trivial if needed. Upgrading to GDAL 3.9 is a problem in certain environments due to its increased requirements.

edwardhartnett commented 1 month ago

refactoring_FillValue to NC_FillValue causes other breakage.

Isn't _FillValue still defined?

WardF commented 1 month ago

It's not, due to conflicts with libstdc++ 18 headers, see the conversation in #2858.