[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[netCDF #QWK-263616]: a quesiton when using netcdf in fortran90



> Hi,
> When I try to compile a f90 file which includes the module of netcdf,
> something was wrong.
> Here is the code:
> 
> program simple_xy_wr
> use NETCDF
> implicit none
> character (len = *), parameter :: FILE_NAME = "simple_xy.nc"
> integer, parameter :: NDIMS = 2
> integer, parameter :: NX = 6, NY = 12
> integer :: ncid, varid, dimids(NDIMS)
> integer :: x_dimid, y_dimid
> integer :: data_out(NY, NX)
> integer :: x, y
> do x = 1, NX
> do y = 1, NY
> data_out(y, x) = (x - 1) * NY + (y - 1)
> end do
> end do
> 
> call check( nf90_create(FILE_NAME, NF90_CLOBBER, ncid) )
> call check( nf90_def_dim(ncid, "x", NX, x_dimid) )
> call check( nf90_def_dim(ncid, "y", NY, y_dimid) )
> 
> dimids =  (/ y_dimid, x_dimid /)
> call check( nf90_def_var(ncid, "data", NF90_INT, dimids, varid) )
> call check( nf90_enddef(ncid) )
> call check( nf90_put_var(ncid, varid, data_out) )
> call check( nf90_close(ncid) )
> ........
> end program simple_xy_wr
> When I use gfortran *.f90, then it shows:
> 
> xhxue@xhxue-desktop:~/Research/fortran$ gfortran netcdf-test.f90
> /tmp/cc4Aw414.o: In function `MAIN__':
> netcdf-test.f90:(.text+0xc7): undefined reference to `__netcdf__nf90_create'
> netcdf-test.f90:(.text+0xff): undefined reference to
> `__netcdf__nf90_def_dim'
> netcdf-test.f90:(.text+0x137): undefined reference to
> `__netcdf__nf90_def_dim'
> netcdf-test.f90:(.text+0x211): undefined reference to
> `__netcdf__nf90_def_var_manydims'
> netcdf-test.f90:(.text+0x24a): undefined reference to
> `__netcdf__nf90_enddef'
> netcdf-test.f90:(.text+0x2d2): undefined reference to
> `__netcdf__nf90_put_var_2d_fourbyteint'
> netcdf-test.f90:(.text+0x2eb): undefined reference to `__netcdf__nf90_close'
> /tmp/cc4Aw414.o: In function `check.592':
> netcdf-test.f90:(.text+0x37b): undefined reference to
> `__netcdf__nf90_strerror'
> collect2: ld return 1
> The netcdf.mod has been input in the same dir same .f90 file and netcdf
> was compiled and installed using gfortran, so what is the reason for it ?
> Could you please help me figure it out?
> 
> ---------------------------------------------------
> Xianghui XUE
> 
> 

If you built netCDF, and ran "make check" you can see the options that are 
required to link an f90 program.

Thanks,

Ed

Ticket Details
===================
Ticket ID: QWK-263616
Department: Support netCDF
Priority: High
Status: Closed