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

[netCDF #SPU-502397]: Issues With NetCDF Compiling in FORTRAN



Hi David,

> I'm back again with another question. We are trying to link the netcdf
> lib with other object files that we have for this one project. The only
> problem is that we mix in FORTRAN with C functions. I think because of
> that it requires that the main program file to be linked as a .f file
> and not a .o file. Therefore I can not just use
> f77 -c -fno-second-underscore -I/home/trangd/netcdf/include test.f
> f77 -o test test.o -L/home/trangd/netcdf/lib -lnetcdff -lnetcdf
> 
> I know I created a library that makes a .a file and links my C functions
> that way.
> And I saw that in the lib folder there are .a files. Can I link the
> netCDF libraries that way?
> 
> We are doing something like this:
> 
> If our FORTRAN file we have this:
> SUBROUTINE HANDLE_ERR(ERRCODE)
> IMPLICIT NONE
> c INCLUDE 'netcdf.inc'
> INTEGER ERRCODE
> 
> call nc_strerror(ERRCODE)
> STOP 2
> END
> 
> And this is how our makefile looks like:
> 
> f77 -I. -O3 -o bin/wind_ret source_code/wind_ret.f sort.o genws.o \
> windmodels.o twoscale.o degree_trig_funcs.o \
> read_header.o read_header_inimglincol.o \
> get_llpolycoef.o read_latlongpoly.o
> get_polytransval.o fio_v4.0/fio_lib.a \
> 
> /home/trangd/GDYNAMICS_GP70/netcdf/lib/libnetcdf.a
> /home/trangd/GDYNAMICS_GP70/netcdf/lib/libnetcdff.a
> /tmp/ccha4udd.o: In function `handle_err__':
> wind_ret.f:(.text+0x4207): undefined reference to `nc_strerror__'
> collect2: ld returned 1 exit status
> make: *** [wind_ret] Error 1
> 
> I hope we can find a solution to this.

It looks like you have the libraries in the wrong order, because the
netCDF Fortran library, libnetcdff.a, contains functions that call the
netCDF C library, libnetcdf.a.  If you just reverse the order of those
two libraries, it should work better.

--Russ

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



Ticket Details
===================
Ticket ID: SPU-502397
Department: Support netCDF
Priority: Normal
Status: Closed


NOTE: All email exchanges with Unidata User Support are recorded in the Unidata inquiry tracking system and then made publicly available through the web. If you do not want to have your interactions made available in this way, you must let us know in each email you send to us.