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

[netCDF #IWW-904637]: problem with netcdf and gfortran



Hi Lei,

> I was not aware of any mailing list with netcdf support so I sent
> this email to you.
> 
> I am trying to build a fortran code, but my netcdf library is not
> referenced correctly.
> 
> Here is the error message (after typing gfortran netcdf-include.f90
> -L/sw/opt/netcdf7/lib -lnetcdf -I/sw/opt/netcdf7/include):
> 
> Undefined symbols for architecture x86_64:
> "_nf_open_", referenced from:
> _MAIN__ in cc6aBlZC.o
> ld: symbol(s) not found for architecture x86_64
> collect2: ld returned 1 exit status
> 
> I installed netcdf7 using fink default option and here is the
> configuration using nc-config --all:
> 
> This netCDF 4.1.3 has been built with the following features:
> 
> --cc        -> gcc
> --cflags    ->  -I/sw/opt/netcdf7/include -I/sw/include
> --libs      -> -L/sw/opt/netcdf7/lib -lnetcdf
> 
> --cxx       -> g++
> --has-c++   -> yes
> 
> --fc        -> ifort
> --fflags    ->  /sw/opt/netcdf7/include
> --flibs     -> -L/sw/opt/netcdf7/lib -lnetcdff -lnetcdf
> --has-f77   -> no
> --has-f90   -> no
> 
> --has-dap   -> yes
> --has-nc2   -> yes
> --has-nc4   -> yes
> --has-hdf5  -> yes
> --has-hdf4  -> no
> --has-pnetcdf-> no
> --has-szlib ->
> 
> --prefix    -> /sw
> --includedir-> /sw/opt/netcdf7/include
> --version   -> netCDF 4.1.3
> 
> I also attached my very simple fortran code. Please advise me on what
> might cause this problem and how to solve it. Thank you very much for
> your time and help,

Try compiling as follows:

 ifort -I/sw/opt/netcdf7/include netcdf-include.f90 -o myprog 
-L/sw/opt/netcdf7/lib -lnetcdff -lnetcdf

or use gfortran instead of "ifort" if that doesn't work.  One or the other of 
these ought to result in 
an executable program named "myprog".  The -I option must appear before the 
name of the
source file to tell the compiler where to find the .mod files.  Some Fortran 
compilers use -M
instead of -I for this.  The -L and -l options must appear after the source 
file name.  The
-lnetcdff option must appear before -lnetcdf because the Fortran library is 
separate from the
C library for netCDF and calls C functions.

The output of nc-config that you showed says the library was compiled with 
"ifort" rather than gfortran,
so it may be necessary to use ifort to compile and link Fortran programs if 
gfortran and ifort have
different conventions for how to call C functions from Fortran.

--Russ

Russ Rew                                         UCAR Unidata Program
address@hidden                      http://www.unidata.ucar.edu



Ticket Details
===================
Ticket ID: IWW-904637
Department: Support netCDF
Priority: Normal
Status: Closed