Question

I'm trying to build a f90 program that uses NetCDF libraries. The compilation of the objects goes well. But at the linking stage, which links with NetCDF libraries, there's a problem:

gfortran-mp-4.7 -g -O2 -Wall -o myProg myObj1.o myObj2.o /opt/local/lib/libnetcdff.a /opt/local/lib/libnetcdf.a

Undefined symbols for architecture x86_64:
  "_H5Aclose", referenced from:
      _nc4_rec_read_vars in libnetcdf.a(libnetcdf4_la-nc4file.o)
      _nc4_rec_read_vars_cb in libnetcdf.a(libnetcdf4_la-nc4file.o)
      _nc4_rec_write_metadata in libnetcdf.a(libnetcdf4_la-nc4hdf.o)
      _write_attlist in libnetcdf.a(libnetcdf4_la-nc4hdf.o)
      _nc4_rec_write_types in libnetcdf.a(libnetcdf4_la-nc4hdf.o)
      _write_netcdf4_dimid in libnetcdf.a(libnetcdf4_la-nc4hdf.o)
 .
 . [Similar paragraphs]
 .
  "_curl_easy_strerror", referenced from:
      _ocfetchurl_file in libnetcdf.a(liboc_la-ochttp.o)
      _ocfetchurl in libnetcdf.a(liboc_la-ochttp.o)
      _ocfetchlastmodified in libnetcdf.a(liboc_la-ochttp.o)
      _ocping in libnetcdf.a(liboc_la-ochttp.o)
  "_curl_version_info", referenced from:
      _oc_curl_protocols in libnetcdf.a(liboc_la-occurlfunctions.o)
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status

I'm not a very experienced programmer, but what I get from this is that apparently it cannot find stuff like _H5Aclose. Google tells me this belongs to a hdf5 library. But I seem to have this:

pwd:/opt/local/include >> ls | grep hdf
hdf5.h
hdf5_hl.h

I've also tried adding these paths explicitly to the linker (although this was not specified in the makefile)

gfortran-mp-4.7 -g -O2 -Wall -o myProg myObj1.o myObj2.o -L/opt/local/include -L/opt/local/lib /opt/local/lib/libnetcdff.a /opt/local/lib/libnetcdf.a

gfortran-mp-4.7 -g -O2 -Wall -o myProg myObj1.o myObj2.o -I/opt/local/include -I/opt/local/lib /opt/local/lib/libnetcdff.a /opt/local/lib/libnetcdf.a

But I get the same error message. I'm on Mac OS 10.8, and have installed both gcc (which came with gfortran) and netcdf-fortran from macports. Anybody know's what's wrong, or how I should proceed to figure it out?

Was it helpful?

Solution

NetCDF4 and HDF5 both come with helper applications

  • nf-config
  • nc-config
  • h5fc
  • h5cc

Did they get installed? I would use them by default, for your case:

gfortran-mp-4.7 -g -O2 -Wall -o myProg myObj1.o myObj2.o `nf-config --fflags --flibs`
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top