[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[netCDF #ESV-218399]: problems linking fortran with netcdf.inc
- Subject: [netCDF #ESV-218399]: problems linking fortran with netcdf.inc
- Date: Mon, 30 Aug 2010 10:36:37 -0600
Hi Kris,
> I've written code to read a netcdf file in fortran 90. I have the
> netcdf 4.0.1 software installed on my Linux machine. Here are my
> compile commands:
>
> gfortran -c -I/usr/local/netcdf/include ncread_test.f90
> gfortran -o ncread_test ncread_test.o -L/usr/local/netcdf/lib -lnetcdf
>
> In my code, I have the statement: INCLUDE 'netcdf.inc'
>
> When I compile, I get a slew of "undefined reference to" messages:
>
> ncread_test.f90:(.text+0x8b): undefined reference to `nf_open'
> ncread_test.f90:(.text+0x13a): undefined reference to `nf_strerror'
> ncread_test.f90:(.text+0x189): undefined reference to `nf_inq_varid'
> ncread_test.f90:(.text+0x238): undefined reference to `nf_strerror'
> ncread_test.f90:(.text+0x279): undefined reference to `nf_inq_varndims'
>
> In my include statement, I have tried including the full path to the
> netcdf.inc, but this did not work either. What am I doing wrong
> here
If you built shared rather than static libraries using the configure option
--enable-shared, or if you requested a separate Fortran library using the
configure option --enable-separate-fortran, then you need to specify one
more library on the link command, -lnetcdff. So instead of
gfortran -o ncread_test ncread_test.o -L/usr/local/netcdf/lib -lnetcdf
try
gfortran -o ncread_test ncread_test.o -L/usr/local/netcdf/lib -lnetcdf
-lnetcdff
If that doesn't work, make sure you don't have an older shared library for
netCDF
installed some place that will be searched first, such as /usr/lib. If so and
if
that library didn't include a Fortran interface, that would also cause the
symptom
you are reporting.
--Russ
Russ Rew UCAR Unidata Program
address@hidden http://www.unidata.ucar.edu
Ticket Details
===================
Ticket ID: ESV-218399
Department: Support netCDF
Priority: Normal
Status: Closed