【问题标题】:Compiling Fortran netCDF programs with all available libraries使用所有可用库编译 Fortran netCDF 程序
【发布时间】:2015-07-01 01:50:10
【问题描述】:

首先我已经阅读了这个主题,但我无法编译我的代码。 Compiling Fortran netCDF programs on Ubuntu

我在 UBUNTU 14.04 上编译一个使用 NetCDF 的 fortran 程序。我有这样的编译错误:

terrain.f:(.text+0x17efd): undefined reference to 'ncopn_'
terrain.f:(.text+0x18111): undefined reference to 'ncopn_'
terrain.f:(.text+0x187cc): undefined reference to 'ncclos_'
terrain.f:(.text+0x187ea): undefined reference to 'ncclos_'

它肯定说我没有 netcdf fortran 库。但是我根据这些网页安装了 zlib、HDF5、netcdf C 和 netcdf Fortran,并带有禁用共享和禁用 dap 选项。

http://www.unidata.ucar.edu/software/netcdf/docs/build_default.html http://www.unidata.ucar.edu/software/netcdf/docs/netcdf-fortran-install.html

这是 nc-config --libs 命令的结果:

-L/usr/local/lib -L/usr/local -lnetcdf -lhdf5_hl -lhdf5 -ldl -lm -lz

这是 nf-config --flibs 命令的结果:

-L/usr/local/lib -lnetcdff -L/usr/local/lib -lnetcdf -lnetcdf -lhdf5_hl -lhdf5 -lz

我用这个命令构建我的项目:

gfortran terrain.f -I/usr/local/include -L/usr/local/lib -lnetcdff -lnetcdf -lhdf5_hl -lhdf5 -lz -lm -ldl

这有什么问题?

编辑: 我在配置 netcdf C 和 netcdf fortran 时使用 --disable-netcdf-4 选项,我可以编译我的代码。所以这是HDF5的问题。

【问题讨论】:

  • 你能告诉我们你的 Fortran 代码吗?或者更好的是一个最小的例子?
  • 我的代码太长了。但我可以在其他一些系统上运行它,并且它有适当的包含。我现在在我的系统中运行它而不安装 hdf5 和 --disable-netcdf-4 选项。
  • 让我吃惊的是,引用是ncopn_,而不是nf90_open__ 或类似的东西。
  • 这些是旧语法,你可以在 unidata 网站上看到它们。

标签: compilation fortran netcdf


【解决方案1】:

这并不是真正的答案,但您需要提供更多信息。编写一个简单的程序,然后向我们展示代码。然后向我们展示你用来尝试编译的命令。

这里有两个例子:

Fortran 77:

$ cat test_nc.f

      PROGRAM TEST_NC
      IMPLICIT NONE
      include 'netcdf.inc'
      INTEGER ncid, nc_err

      nc_err = nf_open('test.nc', nf_nowrite, ncid)
      nc_err = nf_close(ncid)
      END PROGRAM TEST_NC

$ gfortran test_nc.f -o test_nc `nf-config --fflags --flibs`

Fortran 90:

$ cat test_nc.f90
program test_nc
    use netcdf
    implicit none
    integer :: ncid, nc_err

    nc_err = nf90_open('test.nc', nf90_nowrite, ncid)
    nc_err = nf90_close(ncid)
end program test_nc

$ gfortran test_nc.f90 -o test_nc `nf-config --fflags --flibs`

这两个都在我的系统上编译,没有错误甚至警告。

【讨论】:

    猜你喜欢
    • 2012-12-06
    • 1970-01-01
    • 1970-01-01
    • 2020-01-03
    • 2023-03-11
    • 2021-04-15
    • 1970-01-01
    • 2014-11-16
    • 1970-01-01
    相关资源
    最近更新 更多