This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
Ashish, [Sorry for the delay in responding. Severe snow made travel to work impossible.] The link-command that you used: g77 -o odbtest.out odbtest.f -lodb -L/home/aarora/netcdf-3.5.0 -lnetcdf probably has an incorrect value for the "-L" option. The netCDF library should be in the directory /home/aarora/netcdf-3.5.0/lib rather than /home/aarora/netcdf-3.5.0 See if this is true. If so, then you should be able to link your program using the command g77 -o odbtest.out odbtest.f -lodb -L/home/aarora/netcdf-3.5.0/lib -lnetcdf If this fails, then check that the netCDF library contains the global symbol "ncopn_" by executing the command nm -g /home/aarora/netcdf-3.5.0/lib/libnetcdf.a | grep ncopn_ Regards, Steve Emmerson <http://www.unidata.ucar.edu> >Date: Wed, 19 Mar 2003 14:38:37 -0500 >From: ashish arora <address@hidden> >Organization: Kent University >To: Steve Emmerson <address@hidden> >Subject: RE: 20030113: netCDF library link problem: missing f77 interface > > Dear Steve, > > If you remember,I contacted you regarding netCDF library linking problem. > After following all the steps suggested by you,i thought it worked,but it is > not creating odbtest.out when we give g77 command and producing the same > "undefined references" errors for the subroutines. > I am sending you the document of all the steps followed.Please look into it > and suggest me the alternative path since I am going for a meeting in spring > break and I need this running before 21st march. > > Please help. > > The steps followed goes as given below: > > Installing NETCDF libraries > > (1) If we want to run a fortran program which uses NETCDF libraries for its > execution,we need to download and > install NETCDF libraries.After we install these libraries,an archive of these > linraries is formed with the name "libnetcdf.a" > which should be present in the folder which contains the fortran code which > is > required to compiled. > > (2) There is a possibility that the downloaded netcdf libraries may not > contain all the files which may produce different > kind of errors while we try to compile and run the fortran code. > > (3) One error would be of "undefined reference" to the subroutines which are > linked to the main fortran code.This is a very > common and frequent error when working with NETCDF libraries.This kind of > error is mainly due to problem in linking of these > libraries with the main fortran code. > > This error looks something like this: > > /tmp/ccmKEQjM.o: In function `odb_open__': > /tmp/ccmKEQjM.o(.text+0x678): undefined reference to `ncopn_' .. > > The steps which I took to resolve this situation with kind help of Mr.Steve > Emmerson and Dr.Donna Witter were: > > (a) First,we look for the listings of global symbols in the downloaded NETCDF > library. > This can be done by executing the command: > > $ nm -g /home/aarora/netcdf-3.5.0/src/libnetcdf.a > > These are the global symbols which are needed to be present: > > attr.o: > dim.o: > error.o: > libvers.o: > nc.o: > ncio.o: > ncx.o: > putget.o: > string.o: > v1hpg.o: > v2i.o: > var.o: > The module "fort-v2compat" is not in the above list. This means that that > module was not added to the netCDF library > when the netCDF package was installed. > > This means, we necessarily need to have all the modules in the listings > including "fort-v2compat" which was not present in > the libraries I installed for the execution of the program. > > (b) To determine that why that module mentioned above wasn't added to the > library,we need to look into the files > "configure.log","config.log" and "make.log" which are described near the end > of the file "INSTALL.html" in the top-level > source directory of i.e. "src" in this case of netCDF package. > > If the above mentioned module "fort-v2compat" is missing the we will surely > see errors appearing in the above mentioned log > files. > > When we run a command: > > If, however, you are using a standard shell (e.g. "sh", "ksh", "bash"),then > the following command should work: > > $ ./configure >configure.log 2>&1 (In this case,we use this command) > > or > > If you are using a csh-like user-shell (e.g. "csh", "tcsh"), then the > following command should work: > > $ ./configure &>! configure.log > > The "configure.log" file is created by you when you redirect the standard > output and standard error of the "configure" > script to the file "configure.log". The syntax for doing this depends on your > user shell. > > Then we run make command: > > We get the output shown below(with errors): > > make[1]: Entering directory `/home/aarora/netcdf-3.5.0/src' > > > > Making `all' in directory /home/aarora/netcdf-3.5.0/src/libsrc > > > > make[2]: Entering directory > `/home/aarora/netcdf-3.5.0/src/libsrc' > > cc -c -O -I. -DNDEBUG attr.c > > cc -c -O -I. -DNDEBUG dim.c > > cc -c -O -I. -DNDEBUG error.c > > cc -c -O -I. -DNDEBUG -DVERSION=`cat ../VERSION` libvers.c > > cc -c -O -I. -DNDEBUG nc.c > > cc -c -O -I. -DNDEBUG ncio.c > > cc -c -O -I. -DNDEBUG ncx.c > > cc -c -O -I. -DNDEBUG putget.c > > cc -c -O -I. -DNDEBUG string.c > > cc -c -O -I. -DNDEBUG v1hpg.c > > cc -c -O -I. -DNDEBUG v2i.c > > cc -c -O -I. -DNDEBUG var.c > > ar cru libnetcdf.a attr.o dim.o error.o libvers.o nc.o ncio.o > ncx.o putget.o > > string.o v1hpg.o v2i.o var.o > > ranlib libnetcdf.a > > make[2]: Leaving directory > `/home/aarora/netcdf-3.5.0/src/libsrc' > > > > Returning to directory /home/aarora/netcdf-3.5.0/src > > > > make[1]: Leaving directory `/home/aarora/netcdf-3.5.0/src' > > make[1]: Entering directory `/home/aarora/netcdf-3.5.0/src' > > > > Making `all' in directory /home/aarora/netcdf-3.5.0/src/fortran > > > > make[2]: Entering directory > `/home/aarora/netcdf-3.5.0/src/fortran' > > cc -c -O -I../libsrc -DNDEBUG fort-attio.c > > In file included from ncfortran.h:13, > > from fort-attio.c:6: > > cfortran.h:134:3: #error "cfortran.h: Can't find your > environment among: - > > MIPS cc and f77 2.0. (e.g. Silicon Graphics, DECstations, ...) > - > IBM > > AIX XL C and FORTRAN Compiler/6000 Version 01.01.0000.0000 - > VAX > VMS > > CC 3.1 and FORTRAN 5.4. - Alpha VMS DEC C > > 1.3 and DEC FORTRAN 6.0. - Alpha OSF DEC C and > > DEC Fortran for OSF/1 AXP Version 1.2 - Apollo DomainOS 10.2 > > (sys5.3) with f77 10.7 and cc 6.7. - CRAY > > > > - NEC SX-4 SUPER-UX - > > CONVEX - Sun > > > > - PowerStation Fortran with Visual C++ - > > HP9000s300/s700/s800 Latest test with: HP-UX A.08.07 A 9000/730 > - > > LynxOS: cc or gcc with f2c. - > > VAXUltrix: vcc,cc or gcc with f2c. gcc or cc with f77. - > > > > f77 with vcc works; but missing link magic for f77 I/O. - NO > > fort. None of gcc, cc or vcc generate required names. - f2c : > Use > > #define f2cFortran, or cc -Df2cFortran - NAG f90: Use > > #define NAGf90Fortran, or cc -DNAGf90Fortran - Absoft UNIX F77: > > Use #define AbsoftUNIXFortran or cc -DAbsoftUNIXFortran - > Absoft > Pro > > Fortran: Use #define AbsoftProFortran - Portland Group Fortran: > Use > > #define pgiFortran" > > make[2]: *** [fort-attio.o] Error 1 > > make[2]: Leaving directory > `/home/aarora/netcdf-3.5.0/src/fortran' > > make[1]: *** [subdir_target] Error 1 > > make[1]: Leaving directory `/home/aarora/netcdf-3.5.0/src' > > make: *** [fortran/all] Error 2 > > The above error indicates that the Fortran-calling-C interface wasn't told > what conventions to use. > > (c) In order to fix this problem, we need to look into steps A, D, and E, > which are described near the end of the file > INSTALL.html in the top-level source directory. > > If these steps produce errors,the please try the following: > > 1. Go to the top-level source directory. > > 2. Perform steps 3 and 4, which are described near the end of the file > INSTALL.html. > > 3. Set the following environment variables to the indicated values: > > Variable Value CC /usr/bin/gcc > CPPFLAGS -Df2cFortran > FC /usr/bin/f77 > FFLAGS -Wno-globals > CXX /usr/bin/g++ > > Note that the variable "CPPFLAGS" is set to "-Df2cFortran" > > The way that you set these variables will depend on your user-shell: > > Standard shell (e.g. sh, ksh, bash): > > export CPPFLAGS=-Df2cFortran > ... > > csh-like shell (e.g. csh, tcsh): > > setenv CPPFLAGS -Df2cFortran > ... > > 4. Perform steps 6 through 9, which are described near the end of the file > INSTALL.html. > > The detailed description of how to set environment variable of step 3 is as > follows: > > For standard UNIX shells (e.g. "sh", "ksh", "bash"): > > We first execute command: > > $ make distclean > > Then we set environment variable on the command prompt remaining in the top > level source directory of netCDF package: > > export CC=/usr/bin/gcc > export CPPFLAGS=-Df2cFortran > export FC=/usr/bin/f77 > export FFLAGS=-Wno-globals > export CXX=/usr/bin/g++ > After the environment variables are set, we again execute the "configure" > command: > > $./configure >configure.log 2>&1 > > For csh-like shells (e.g. "csh", "tcsh"): > > $ make distclean > ... > setenv CC /usr/bin/gcc > setenv CPPFLAGS -Df2cFortran > setenv FC /usr/bin/f77 > setenv FFLAGS -Wno-globals > setenv CXX /usr/bin/g++ > ./configure >&! configure.log > > Note that you should execute the command "make distclean" before executing > the "configure" script. Don't worry if this command fails or even fails to > execute. > > (d) After setting up the environment, we compile the fortran code by linking > to netCDF libraries using following command: > > g77 -o odbtest.out odbtest.f -lodb -L/home/aarora/netcdf-3.5.0 > -lnetcdf > > You should be able to read about the "-L" and "-l" options in the g77(1) > manual page. > > After this code should work fine,but its not doing so. > Please look into the matter and suggest me changes by tomorrow if possible. > > Thanks Alot, > Ashish Arora > >