Troubleshooting - Alexander-Barth/octave-netcdf GitHub Wiki

recompile with -fPIC

On Linux with AMD/Intel 64 bit you are seeing:

"a local symbol" can not be used when making a shared object; recompile with -fPIC 
/usr/lib/gcc/x86_64-linux-gnu/3.4.6/../../../../lib/libnetcdf.a: could not read symbols: Bad value

well, this means that your have to recompile NetCDF with the compiler option -fPIC, which can be achieved by setting the following configure option:

./configure --with-pic

HDF5 library version mismatched error

Error while reading a netcdf 4 file:

Warning! ***HDF5 library version mismatched error***
The HDF5 header files used to compile this application do not match
the version used by the HDF5 library to which this application is linked.
Data corruption or segmentation faults may occur if the application continues.
This can happen when an application was compiled by one version of HDF5 but
linked with a different version of static or shared HDF5 library.
You should recompile the application or check your shared library related
settings such as 'LD_LIBRARY_PATH'.
You can, at your own risk, disable this warning by setting the environment
variable 'HDF5_DISABLE_VERSION_CHECK' to a value of '1'. 
Setting it to 2 or higher will suppress the warning messages totally.
Headers are 1.8.8, library is 1.8.5
       SUMMARY OF THE HDF5 CONFIGURATION
       =================================
General Information:
-------------------
          HDF5 Version: 1.8.5-patch1
[...]

make sure that octave and netcdf was compiled with the same HDF5 library.

Multiple NetCDF libaries or libaries at non-standard location

Check the output of the shell commands:

which nc-config 
nc-conflig --libs

Does this correspond to the library that you want to use?

If not, define your PATH and LD_LIBRARY_PATH (in your .bashrc and in your current shell)

export PATH="/path/to/the/right/bin:$PATH"
export LD_LIBRARY_PATH="/path/to/the/right/lib:$LD_LIBRARY_PATH"

Crash when setting _FillValue with ncwriteatt

The following code crashes Octave with the netcdf packages AND matlab (R2013a):

>> nccreate(fname,'u_obs','Dimensions',{'x',182,'y',149,'t',inf},'FillValue',-9999.) 
>> ncwriteatt(fname,'u_obs','_FillValue',-9999.)
------------------------------------------------------------------------
       Segmentation violation detected at Thu Mar 26 13:38:28 2015
------------------------------------------------------------------------
[...]
Stack Trace (from fault):
[  0] 0x00007f93e33b8226 /opt/matlab-R2013a/toolbox/matlab/imagesci/+netcdf/private/../../../../../bin/glnxa64/libnetcdf.so.7+00623142 nc4_rec_write_metadata+00001286
[  1] 0x00007f93e33a9909 /opt/matlab-R2013a/toolbox/matlab/imagesci/+netcdf/private/../../../../../bin/glnxa64/libnetcdf.so.7+00563465
[...]

Thus bug is probably due to a bug in the NetCDF library https://bugtracking.unidata.ucar.edu/browse/NCF-187, which is currently not fixed (as for 26 March 2015). This bug could also be reproduced with the current version of the NetCDF library 4.3.3.1.

As a work-around, one should use define the FillValue during the call of nccreate:

fname = 'test.nc'
delete(fname)
nccreate(fname,'u_obs','Dimensions',{'x',182},'FillValue',-9999.)

Installation fails

You get the error message:

netcdf_constants.h: In function ‘void init()’:
netcdf_constants.h:10:47: error: ‘NC_UBYTE’ was not declared in this scope
  netcdf_constants["NC_UBYTE"] = octave_value(NC_UBYTE);

You must use the NetCDF library in version 4.1 (or later).

Libraries not found

The location of the necessary libraries (netCDF and HDF5) are normally detected using nc-config. If this does not work (e.g. using static libraries as this is the case for Mac OS X homebrew), you can also set CPPFLAGS and OCT_LINK_DEPS environement variable in a bash shell before starting octave from the same shell.

export CPPFLAGS="-I/path/to/netcdf/include -I/path/to/hdf5/include $(mkoctfile -p CPPFLAGS)";
export OCT_LINK_DEPS="-L/path/to/netcdf/lib -L/path/to/netcdf/lib -lnetcdf -lhdf5_hl -lhdf5 -lz -lm"

More information about the libraries necessary for netcdf can be found here.

Libraries in non-standard location

If libraries are installed manually (i.e. without the package manager) in a non-standard location, you must set several environment variables to install and run octave:

export PATH=/path/to/netcdf/bin/:$PATH
export LD_LIBRARY_PATH=/path/to/netcdf/lib/:$LD_LIBRARY_PATH

(by substituting /path/to/netcdf/...). If you are unfamiliar with environment variables you might want to read the documentation or the Linux documentation. The directory /path/to/netcdf/bin/ should contain the script nc-config and the directory /path/to/netcdf/lib/ should contain a file starting with libnetcdf.so (e.g. libnetcdf.so.7). The variables. Note that LD_LIBRARY_PATH has to be set every-time before you start octave.

By using the library NetCDF from your package manager (which installs in "standard" location), all these troubles would disappear.