-
Notifications
You must be signed in to change notification settings - Fork 280
Description
This is a report of a problem encountered when building the science/netcdf-cxx port on FreeBSD, against libc++ 18 headers. The reason I am filing an issue in this project instead, is that the actual error is caused by a problem in the netcdf.h
header, which is included from netcdf-cxx.
When you attempt to build netcdf-cxx against installed netcdf-c headers, several compile errors are produced, similar to:
libtool: compile: c++ -DHAVE_CONFIG_H -I. -I.. -fPIC -DPIC -isystem /usr/local/include -O2 -pipe -fstack-protector-strong -isystem /usr/local/include -fno-strict-aliasing -isystem /usr/local/include -MT ncAtt.lo -MD -MP -MF .deps/ncAtt.Tpo -c ncAtt.cpp -fPIC -DPIC -o .libs/ncAtt.o
In file included from ncAtt.cpp:1:
In file included from ./ncAtt.h:2:
In file included from ./ncException.h:3:
In file included from /usr/include/c++/v1/iostream:44:
In file included from /usr/include/c++/v1/istream:170:
In file included from /usr/include/c++/v1/ostream:187:
In file included from /usr/include/c++/v1/bitset:133:
/usr/include/c++/v1/__bit_reference:176:16: error: expected ',' or '>' in template-parameter-list
176 | template <bool _FillValue, class _Cp>
| ^
/usr/local/include/netcdf.h:113:25: note: expanded from macro '_FillValue'
113 | #define _FillValue "_FillValue"
| ^
In file included from ncAtt.cpp:1:
In file included from ./ncAtt.h:2:
In file included from ./ncException.h:3:
In file included from /usr/include/c++/v1/iostream:44:
In file included from /usr/include/c++/v1/istream:170:
In file included from /usr/include/c++/v1/ostream:187:
In file included from /usr/include/c++/v1/bitset:133:
/usr/include/c++/v1/__bit_reference:176:26: error: expected unqualified-id
176 | template <bool _FillValue, class _Cp>
| ^
/usr/include/c++/v1/__bit_reference:1010:18: error: expected ',' or '>' in template-parameter-list
1010 | template <bool _FillValue, class _Dp>
| ^
/usr/local/include/netcdf.h:113:25: note: expanded from macro '_FillValue'
113 | #define _FillValue "_FillValue"
| ^
In file included from ncAtt.cpp:1:
In file included from ./ncAtt.h:2:
In file included from ./ncException.h:3:
In file included from /usr/include/c++/v1/iostream:44:
In file included from /usr/include/c++/v1/istream:170:
In file included from /usr/include/c++/v1/ostream:187:
In file included from /usr/include/c++/v1/bitset:133:
/usr/include/c++/v1/__bit_reference:1010:28: error: expected member name or ';' after declaration specifiers
1010 | template <bool _FillValue, class _Dp>
| ^
4 errors generated.
The problem is that _FillValue
is a macro defined in netcdf.h
, but it conflicts with a template parameter name in libc++'s __bit_reference
header. In general, identifiers starting with _
are reserved for the system headers, so in my opinion netcdf.h
should be adjusted.
However, it looks like the macro name itself is used in a lot of places in netcdf itself, and possibly also in derived projects such as netcdf-cxx. Therefore, I would like to ask you how much breakage would be expected, if the macro name was changed to, for example, NC_FillValue
?
For reference, the FreeBSD science/netcdf port is at version 4.9.2, while the science/netcdf-cxx port is at version 4.3.1, but the problem is also present in the current main branch of this project.