Building netcdf4, netcdf4(python) and nco on Ubuntu

Built HDF as

$ ./configure —enable-netcdf-4 —with-hdf5=/usr/local/hdf5 —enable-share

Built netcdf4 as

$ ./configure —prefix=/usr/local/hdf5 —enable-hl —enable-shared

Configure fails for nco trying to link to netcdf. The Ubuntu nco package doesn’t want to read netcdf4 files – it is using a version of netcdf it installs in /usr/lib (the one I built is in /usr/local/lib).

Tried recompiling everything with -fPIC flag, and tried many different ways of specifiying where the netcdf libaries I built in /usr/local were

./configure --enable-netcdf4 --libdir='/usr/local/lib' --prefix='/usr/local' NETCDF4_ROOT='/usr/local' CC='gcc' CFLAGS='' --disable-dap NETCDF_LIB='/usr/local/lib' NETCDF_ROOT='/usr/local'

No dice – configure failed to successfully link to libnetcdf

In a final act of desperation I set NETCDF4_ROOT to /usr instead of /usr/local, linking to the netcdf4 libraries installed by synaptic. Configure works, but make still picks up ncgen in /usr/local instead of /usr. So I set PATH=’/usr/bin:/bin. Still no dice. In the end I moved /usr/local to /usr/local_temp, and ran:

sudo ./configure --enable-netcdf4 --libdir='/usr/lib' --prefix='/usr' NETCDF4_ROOT='/usr' CC='gcc' --disable-dap NETCDF_LIB='/usr/lib' NETCDF_ROOT='/usr' PATH='/usr/bin:/usr/sbin:/bin' --disable-shared

Got further with this approach, but now it fails when building ncap2, both with the latest cvs and the 3.9.5 release code.

Needed to install anltr. Used synaptic. Build went fine after this, but ncks still gives me this error

ac@LOULI:~/runs/lou-10$ ncks -d timestep,0,1
HINT: NC_ENOTNC errors often occur when NCO operators linked to the netCDF3 library attempt to read netCDF4 files. Are your input files netCDF4 format? If so then installing or re-building a netCDF4-compatible version of NCO may solve this problem.
nco_err_exit(): ERROR Short NCO-generated message (usually name of function that triggered error): nco_open()
nco_err_exit(): ERROR Error code is -51. Translation into English with nc_strerror(-51) is "NetCDF: Unknown file format"
nco_err_exit(): ERROR NCO will now exit with system call exit(EXIT_FAILURE)

when run on netcdf4 files. Works ok on netcdf3 files though. At this point I believe the possible problems are:

1. I’m not building the netcdf libraries in /usr/local correctly?
– they work for creating, ncdumping, etc, maybe not built properly for nco to link to.
2. The ubuntu netcdf4 libraries don’t really work for netcdf4 files?
– they certainly appear not to

sudo ./configure --enable-netcdf4 --libdir='/usr/local/lib:/usr/lib' --prefix='/usr/local' NETCDF4_ROOT='/usr/local' CC='gcc' --disable-dap NETCDF_LIB='/usr/lib' NETCDF_ROOT='/usr' PATH='/usr/bin:/usr/sbin:/bin:/usr/local/bin' --disable-shared

I need to leave this for now – the ideal situation is that the packages work out of the box, so the next step is to reinstall the defaulty packages, try to ncks some netcdf4 files from elsewhere, and file a bug report if they don’t work.



  1. Adam said

    Have you made any progress on this? I’m running into similar issues on Fedora 11 and tried similar steps with the same result. Any ideas?

  2. ac12 said

    No, but I might try again soon.

  3. Russell Jones said

    OK, another two years has elapsed :) I’m trying something similar… did you ever get it to work?

RSS feed for comments on this post · TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: