问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/29813922/compiling-fortran-netcdf-programs-with-all-available-libraries