链接f90包括NetCDF代码

时间:2013-12-20 17:39:38

标签: compiler-errors linker macports fortran90 netcdf

我正在尝试构建一个使用NetCDF库的f90程序。对象的编译很顺利。但是在与NetCDF库链接的链接阶段,存在一个问题:

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

我不是一个非常有经验的程序员,但我从中得到的是显然它找不到像_H5Aclose这样的东西。 Google告诉我这属于hdf5库。但我似乎有这个:

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

我也尝试过明确地将这些路径添加到链接器中(虽然这在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

但是我得到了同样的错误信息。我在Mac OS 10.8上安装了gcc(随gfortran一起提供)和netcdf-fortran来自macports。任何人都知道什么是错的,或者我应该如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

NetCDF4和HDF5都带有辅助应用程序

  • NF-配置
  • NC-配置
  • h5fc
  • h5cc

他们安装了吗?对于你的情况,我会默认使用它们:

gfortran-mp-4.7 -g -O2 -Wall -o myProg myObj1.o myObj2.o `nf-config --fflags --flibs`