Compiling Fortran netCDF programs on Ubuntu

前端 未结 2 2032
鱼传尺愫
鱼传尺愫 2021-01-02 18:13

Ok, newb question here.

I\'m trying to compile simple_xy_wr.f90 -- a netCDF example program -- using gfortran on Ubuntu, and I must be doing something pretty silly;

2条回答
  •  误落风尘
    2021-01-02 18:30

    In Ubuntu 12.10, the order of the libraries is the trick (as Hristo suggested):

    
    angelv@palas:~$ gfortran  -o xy -I/usr/include/ -L/usr/lib/  -lnetcdf -lnetcdff simple_xy_wr.f90
    /tmp/ccj95anF.o: In function `check.1847':
    simple_xy_wr.f90:(.text+0x72): undefined reference to `__netcdf_MOD_nf90_strerror'
    /tmp/ccj95anF.o: In function `MAIN__':
    simple_xy_wr.f90:(.text+0x284): undefined reference to `__netcdf_MOD_nf90_create'
    simple_xy_wr.f90:(.text+0x2b6): undefined reference to `__netcdf_MOD_nf90_def_dim'
    simple_xy_wr.f90:(.text+0x2e8): undefined reference to `__netcdf_MOD_nf90_def_dim'
    simple_xy_wr.f90:(.text+0x432): undefined reference to `__netcdf_MOD_nf90_def_var_manydims'
    simple_xy_wr.f90:(.text+0x468): undefined reference to `__netcdf_MOD_nf90_enddef'
    simple_xy_wr.f90:(.text+0x4aa): undefined reference to `__netcdf_MOD_nf90_put_var_2d_fourbyteint'
    simple_xy_wr.f90:(.text+0x4cb): undefined reference to `__netcdf_MOD_nf90_close'
    collect2: error: ld returned 1 exit status
    
    angelv@palas:~$ gfortran  -o xy -I/usr/include/ simple_xy_wr.f90 -L/usr/lib/  -lnetcdf -lnetcdff 
    
    angelv@palas:~$ ./xy 
               0          12          24          36
     *** SUCCESS writing example file simple_xy.nc! 
    

提交回复
热议问题