SysCTypes errors when using NetCDF.chpl?

Viewed 51

I have a simple Chapel program to test the NetCDF module:

use NetCDF;
use NetCDF.C_NetCDF;

var f: int = ncopen("ppt2020_08_20.nc", NC_WRITE);
var status: int = nc_close(f);

and when I compile with:

chpl -I/usr/include -L/usr/lib/x86_64-linux-gnu -lnetcdf hello.chpl

it produces a list of errors about SysCTypes:

$CHPL_HOME/modules/packages/NetCDF.chpl:57: error: 'c_int' undeclared (first use this function)
$CHPL_HOME/modules/packages/NetCDF.chpl:77: error: 'c_char' undeclared (first use this function)
...

Would anyone see what my error is? I tried adding use SysCTypes; to my program, but that didn't seem to have an effect.

1 Answers

Sorry for the delayed response and for this bad behavior. This is a bug that's crept into the NetCDF module which seems not to have been caught by Chapel's nightly testing. To work around it, edit $CHPL_HOME/modules/packages/NetCDF.chpl, adding the line:

public use SysCTypes, SysBasic;

within the declaration of the C_NetCDF module (around line 50 in my copy of the sources). If you would consider filing this bug as an issue on the Chapel GitHub issue tracker, that would be great as well, though we'll try to get this fixed in the next release in any case.

With that change, your program almost compiles for me, except that nc_close() takes a c_int argument rather than a Chapel int. You could either lean on Chapel's type inference to cause this to happen:

var f = ncopen("ppt2020_08_20.nc", NC_WRITE);

or explicitly declare f to be of type c_int:

var f: c_int = ncopen("ppt2020_08_20.nc", NC_WRITE);

And then as one final note, I believe you should be able to drop the -lnetcdf from your chpl command-line as using the NetCDF module should cause this requirement to automatically be added.

Thanks for bringing this bug to our attention!

Related