Unidata / netcdf-fortran

Official GitHub repository for netCDF-Fortran libraries, which depend on the netCDF C library. Install the netCDF C library first.
Other
238 stars 97 forks source link

Compilation error: Undefined symbols for architecture x86_64 #76

Open GeneralDuke9 opened 6 years ago

GeneralDuke9 commented 6 years ago

I tried to compile the "simple_wr_xy.f90" example fortran program that I found on the Unidata website (https://www.unidata.ucar.edu/software/netcdf/examples/programs/). However, it produces the following error:

Undefined symbols for architecture x86_64:
  "___netcdf_MOD_nf90_close", referenced from:
      _MAIN__ in ccjeXgrx.o
  "___netcdf_MOD_nf90_create", referenced from:
      _MAIN__ in ccjeXgrx.o
  "___netcdf_MOD_nf90_def_dim", referenced from:
      _MAIN__ in ccjeXgrx.o
  "___netcdf_MOD_nf90_def_var_manydims", referenced from:
      _MAIN__ in ccjeXgrx.o
  "___netcdf_MOD_nf90_enddef", referenced from:
      _MAIN__ in ccjeXgrx.o
  "___netcdf_MOD_nf90_put_var_2d_fourbyteint", referenced from:
      _MAIN__ in ccjeXgrx.o
  "___netcdf_MOD_nf90_strerror", referenced from:
      _check.3501 in ccjeXgrx.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status

I use the ncarg suite provided by MacPorts, built with the gcc7 option. I have also installed the netcdf-cxx, netcdf-cxx4 and netcdf-fortran ports (installed in that order) and I included the -I/opt/local/include flag in the compilation command.

t-power89 commented 6 years ago

Any luck with this?

lisalenorelowe commented 6 years ago

did you do "-lnetcdf -lnetcdff"

mirfjc commented 5 years ago

I don't know the particulars for the original poster, but the quoted error can be reproduced with a command something like (i.e., not using -lnetcdff):

gfortran simple_xy_wr.f90 -o simple_xy_wr.exe -I/opt/local/include -L/opt/local/lib -lnetcdf

To get the code to compile correctly, one needs to use -lnetcdff:

gfortran simple_xy_wr.f90 -o simple_xy_wr.exe -I/opt/local/include -L/opt/local/lib -lnetcdff

or

gfortran simple_xy_wr.f90 -o simple_xy_wr.exe -I/opt/local/include -L/opt/local/lib -lnetcdf -lnetcdff

For completeness, the other errors associated with not specifying either the -I or -L (when using the macports default install locations) are:

> gfortran simple_xy_wr.f90 -o simple_xy_wr.exe -I/opt/local/include -lnetcdff
ld: library not found for -lnetcdff
collect2: error: ld returned 1 exit status

and:

> gfortran simple_xy_wr.f90 -o simple_xy_wr.exe -L/opt/local/lib -lnetcdf -lnetcdff
simple_xy_wr.f90:19:6:

   use netcdf
       1
Fatal Error: Can't open module file 'netcdf.mod' for reading at (1): No such file or directory