使用所有可用库编译 Fortran netCDF 程序

Had*_*ali 1 fortran compilation netcdf

首先,我已经阅读了这个主题,但我无法编译我的代码。 在 Ubuntu 上编译 Fortran netCDF 程序

我在 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_'
Run Code Online (Sandbox Code Playgroud)

它肯定说我没有 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
Run Code Online (Sandbox Code Playgroud)

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

-L/usr/local/lib -lnetcdff -L/usr/local/lib -lnetcdf -lnetcdf -lhdf5_hl -lhdf5 -lz
Run Code Online (Sandbox Code Playgroud)

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

gfortran terrain.f -I/usr/local/include -L/usr/local/lib -lnetcdff -lnetcdf -lhdf5_hl -lhdf5 -lz -lm -ldl
Run Code Online (Sandbox Code Playgroud)

这是怎么回事?

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

chw*_*w21 5

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

下面是两个例子:

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`
Run Code Online (Sandbox Code Playgroud)

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`
Run Code Online (Sandbox Code Playgroud)

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