使用所有可用的库编译Fortran netCDF程序 [英] Compiling Fortran netCDF programs with all available libraries

查看:416
本文介绍了使用所有可用的库编译Fortran netCDF程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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

  terrain.f :(。text + 0x17efd):对'ncopn_'$ b的未定义引用$ b terrain.f :(。text + 0x18111):未定义对'ncopn_'的引用
terrain.f :(。text + 0x187cc):未定义对'ncclos_'
terrain.f :( text + 0x187ea):对'ncclos_'的未定义引用

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



http://www.unidata.ucar.edu/software/netcdf/docs/build_default.html
http://www.unidata.ucar.edu/软件/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地形.f -I / usr / local / include -L / usr / local / lib -lnetcdff -lnetcdf -lhdf5_hl -lhdf5 -lz -lm -ldl 

这是什么问题? p>

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

解决方案

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



以下是两个示例:



Fortran 77:

  $ cat test_nc.f 

程序TEST_NC
无隐含
包括'netcdf.inc'
整数ncid,nc_err

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

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

Fortran 90:

  $ cat test_nc.f90 
程序test_nc
使用netcdf
隐式无
整数:: ncid,nc_err

nc_err = nf90_open('test.nc',nf90_nowrite,ncid)
nc_err = nf90_close(ncid)
最终程序test_nc

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

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


first of all I've read this topic but I can't compile my code. Compiling Fortran netCDF programs on Ubuntu

I am on UBUNTU 14.04 and compiling a fortran program that uses NetCDF. I have compilation error like this:

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_'

Definitely it says I have not netcdf fortran librarries. But I installed zlib, HDF5, netcdf C and netcdf Fortran according these web pages with disable shared and disable dap options.

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

this is result of nc-config --libs command:

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

this is result of nf-config --flibs command:

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

i build my project with this command:

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

what's wrong with this?

Edit: I use --disable-netcdf-4 option in configuring netcdf C and netcdf fortran and I can compile my code. So it's a problem with HDF5.

解决方案

This isn't really an answer, but you need to produce more info. Write a bare-bones program, and show us the code. Then show us the command you use to try and compile.

Here are two examples:

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`

Both of these compile on my system without errors or even warnings.

这篇关于使用所有可用的库编译Fortran netCDF程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆