【问题标题】:Linking f90 including NetCDF code链接 f90,包括 NetCDF 代码
【发布时间】:2013-12-20 17:39:37
【问题描述】:

我正在尝试构建一个使用 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 这样的东西。谷歌告诉我这属于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 上,并且已经从 macports 安装了 gcc(gfortran 附带)和 netcdf-fortran。有谁知道出了什么问题,或者我应该如何解决?

【问题讨论】:

  • 你的硬盘上有hdf5.mod吗?
  • 不,它不在 /usr、/opt 或 /Applications/Xcode 下,所以我想我没有
  • 我认为拥有hdf5.mod 文件是必要的,但我不使用NetCDF,所以我不是最有资格回答的人。
  • 我尝试重新安装 hdf5(再次从 macports),但没有给我 mod 文件。也许我需要从源代码构建?但我不相信这是缺少的 hdf5,因为我不认为其他未定义的符号,如“_curl_easy_strerror”是 hdf5 的一部分。我认为我必须做错链接
  • 我会从源代码构建,这样你就可以输入./configure --enable-fortran(加上你想要的任何其他选项),以便制作相关的.mod文件。

标签: compiler-errors linker macports fortran90 netcdf


【解决方案1】:

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

  • nf 配置
  • nc 配置
  • h5fc
  • h5cc

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-16
    • 2015-08-21
    • 2020-11-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多