Re: [netcdfgroup] netcdf.h declares non-existing functions

  • To: Dennis Heimbigner <dmh@xxxxxxxxxxxxxxxx>
  • Subject: Re: [netcdfgroup] netcdf.h declares non-existing functions
  • From: Doug Hunt <dhunt@xxxxxxxx>
  • Date: Mon, 30 Apr 2012 15:12:14 -0600 (MDT)
Hi Dennis:  This sounds good to me!

Regards,

  Doug Hunt

dhunt@xxxxxxxx
Software Engineer
UCAR - COSMIC, Tel. (303) 497-2611

On Mon, 30 Apr 2012, Dennis Heimbigner wrote:

Unidata proposes to change this as follows.

1. All the netcdf-4 functions will exist in the netcdf-3
  only library, but will return the error NC_ENOTNC4
  if invoked. This allows runtime testing for netcdf-4 support.
2. The NC_NETCDF4 flag in netcdf.h will only be defined
  it the corresponding library has netcdf-4 support enabled.
  This is so compile-time testing for netcdf-4 can occur.

Comments?

=Dennis Heimbigner
Unidata


Doug Hunt wrote:
Hi Heiko: I made a fix to the logic PDL-NetCDF uses to detect if netcdf-4 support is available. In the previous version, a simple check for the pre-processor symbol NC_NETCDF4 being defined is made--if it is, then netcdf-4 support is found.

Recent netcdf releases, however, have been defining NC_NETCDF4 whether or not netcdf-4 support is actually present (meaning netcdf is compiled with HDF5).

The change I made includes a test compile and link of nc_inq_var_deflate to determine if netcdf-4 support is available. The logic is in Makefile.PL, not netcdf.pd. I've used this procedure before in my PDL-Graphics-PLplot interface and it works well.

I'm sending this to you instead of just putting it on CPAN because (1) I can't get netcdf-4 support compiled in on my machine, so I can't test it properly and (2) you added the netcdf-4 support so I'd like you to look it over.

Could you take a look and see if this makes sense to you? If you've got a netcdf-4 enabled netcdf on one of your systems, it would be great if you could test it out.

Thanks much,

  Doug

dhunt@xxxxxxxx
Software Engineer
UCAR - COSMIC, Tel. (303) 497-2611

On Fri, 27 Apr 2012, Heiko Klein wrote:

Russ,

I'll try to give a better example:

I don't have hdf-libraries installed (at least not in default pathes). First, from a pure ABI point of view:
---------------------------------------------------------------
With netcdf-4.1.2:
./configure --prefix=/disk1/netcdf-4.1.2_install
make
make install

In /disk1/netcdf-4.1.2_install/include:
$ grep nc_def_var_deflate netcdf.h
* function nc_def_var_deflate.  These defines are used there. */
nc_def_var_deflate(int ncid, int varid, int shuffle, int deflate,

In /disk1/netcdf-4.1.2_install/lib:
$ nm libnetcdf.so | grep nc_def_var_deflate

Nothing found, symbol not defined.

--------------------------------------------------------------
New try, all directories removed and new untar:

./configure --prefix=/disk1/netcdf-4.1.2_install --disable-netcdf4
make
make install

In /disk1/netcdf-4.1.2_install/lib:
$ nm libnetcdf.so | grep nc_def_var_deflate

Nothing found, symbol not defined. Still the same.
---------------------------------------------------------------
New try, now 4.2:
$ ./configure --prefix=/disk1/netcdf-4.2_install --disable-netcdf-4
make
make install

In /disk1/netcdf-4.2_install/lib
$ nm libnetcdf.so | grep nc_def_var_deflate

Nothing found, symbol not defined.
---------------------------------------------------------------
A previous build, with hdf5 enabled:
$ nm /disk1/heiko/local/netcdf4.2-rc1/lib/libnetcdf.so | grep nc_def_var_deflate
000299b0 T nc_def_var_deflate
----------------------------------------------------------------




Now, from a API point of view:

a slightly modified simple_xy_wr.c (from http://www.unidata.ucar.edu/software/netcdf/examples/programs/), just enabling compression if netcdf4 is supported by the library:
#ifdef NC_NETCDF4
  /* compress all variables in netcdf4 */
  if ((retval = nc_def_var_deflate(ncid, varid, 0, 1, 3)))
     ERR(retval);
#endif

The program works nicely with netcdf-4.1.1, independently of netcdf4 is enabled or disabled.
$ gcc -c -I/opt/netcdf4.1.1/include/ simple_xy_wr.c
$ gcc -o simple_xy_wr simple_xy_wr.o -L/opt/netcdf4.1.1/lib/ -lnetcdf
No problems


With above 4.2:
$ gcc -c -I/disk1/netcdf-4.2_install/include/ simple_xy_wr.c
No problems.
$ gcc -o simple_xy_wr simple_xy_wr.o -L/disk1/netcdf-4.2_install/lib -lnetcdf
simple_xy_wr.o: In function `main':
simple_xy_wr.c:(.text+0x27d): undefined reference to `nc_def_var_deflate'
collect2: ld returned 1 exit status


With 4.2, but with enabled hdf/netcdf4 support (ok, that's 4.2rc1, but that not the point here):
$ gcc -c -I/disk1/heiko/local/netcdf4.2-rc1/include simple_xy_wr.c
No problems
$ gcc -o simple_xy_wr simple_xy_wr.o -L/disk1/heiko/local/netcdf4.2-rc1/lib -lnetcdf
No problems, generating netcdf4 files.


I see the code of nc_def_var_deflate defined in libdispatch/dvar.c, but it doesn't seem to make it to the library.


Best regards,

Heiko





On 2012-04-26 18:51, Russ Rew wrote:
Heiko,

since netcdf-4.1.2, the netcdf.h file declares all netcdf4 functions,
like nc_def_var_deflate and NC_NETCDF4, even if the library was compiled
without hdf5 support, and does not have these functions.

I have code like

#ifdef NC_NETCDF4
    nc_def_var_deflate(...)
#endif

which worked perfectly with netcdf3 and netcdf4 until 4.1.1. Since
netcdf 4.1.2, this code compiles still, but when the netcdf-library was
not compiled with hdf5 support, the code won't link with the library.
This means, that netcdf since 4.1.2 has a single API, but has different
ABIs depending on netcdf-configure flags. I would suggest adding the
'Extra netcdf4 stuff.' function calls to the netcdf3 code, even if they
are empty, e.g.

int
nc_def_var_deflate(int ncid, int varid, int shuffle, int deflate,
                     int deflate_level)
{
    return NC_NOERR;
}

This means, that netcdf since 4.1.2 has a single API, but has different
ABIs depending on netcdf-configure flags. I would suggest adding the
'Extra netcdf4 stuff.' function calls to the netcdf3 code, even if they
are empty, e.g.

int
nc_def_var_deflate(int ncid, int varid, int shuffle, int deflate,
                     int deflate_level)
{
    return NC_NOERR;
}

Sorry, but I can't duplicate the problem.  This is supposed to be
handled by the "dispatch layer" in netCDF-4.x.  For example, when you
run "make check" on a netCDF-4.2 distribution that has been configured
with "--disable-netcdf-4", it will link and run netCDF-3 tests against
the library, so this would indicate all the public functions declared in
netcdf.h must be implemented.

The following function appears in libdispatch/dvar.c, even when
configured with "--disable-netcdf-4":

int
nc_def_var_deflate(int ncid, int varid, int shuffle, int deflate, int deflate_level)
{
     NC* ncp;
     int stat = NC_check_id(ncid,&ncp);
     if(stat != NC_NOERR) return stat;
return ncp->dispatch->def_var_deflate(ncid,varid,shuffle,deflate,deflate_level); }

I've also just tried building the 4.2 library with --disable-netcdf-4
and --disable-shared, and verified that a netCDF-3 program compiles and
links with the resulting static library.  However, I had to remove
previously built shared libraries from the directory in which I
installed the static library, because the dynamic linker/loader will use
an older installed shared library in preference to a new static library.

I also built a new shared library with --disable-netcdf-4 but without
--disable-shared and verified that a netCDF-3 program could be
successfully linked and run against the resulting shared library.  For
this, I set LD_LIBRARY_PATH to run the resulting program, but other
alternatives would also work, assuming the library is installed in
LIBDIR:

    - add LIBDIR to the `LD_RUN_PATH' environment variable
      during linking
    - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
    - have system administrator add LIBDIR to `/etc/ld.so.conf'

This was all on a Linux system, but our cross-platform tests should
catch such problems on some other systems, such as Solaris, MacOS, and
AIX.

It's possible I've misunderstood the problem.  If so, I'll need more
information to reproduce it.  For now, I think the dispatch layer
implementation already provides the stub functions for 'extra netCDF-4
stuff' that you're requesting ...

--Russ

Note: as Dennis Heimbigner pointed out last week on this list, for now
it's necessary to build netCDF-4.2 with "--disable-dap-remote-tests", at
least until we resolve a problem with the test server, which was moved
from port 8080 to 8081.

--
Dr. Heiko Klein                              Tel. + 47 22 96 32 58
Development Section / IT Department          Fax. + 47 22 69 63 55
Norwegian Meteorological Institute           http://www.met.no
P.O. Box 43 Blindern  0313 Oslo NORWAY


------------------------------------------------------------------------

_______________________________________________
netcdfgroup mailing list
netcdfgroup@xxxxxxxxxxxxxxxx
For list information or to unsubscribe, visit: http://www.unidata.ucar.edu/mailing_lists/

_______________________________________________
netcdfgroup mailing list
netcdfgroup@xxxxxxxxxxxxxxxx
For list information or to unsubscribe, visit: http://www.unidata.ucar.edu/mailing_lists/



  • 2012 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: