[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 20030107: NetCDF Linking problems
- Subject: Re: 20030107: NetCDF Linking problems
- Date: Tue, 07 Jan 2003 16:09:34 -0700
>To: "'address@hidden'" <address@hidden>
>From: "Cross, Scott L DR" <address@hidden>
>Subject: Linking problems
>Organization: Naval Oceanographic Office
>Keywords: 200301071738.h07Hcat18411
Hi Scott,
> Am having problems getting g77 to link the netcdf library during
> compilation/linking I'm running Redhat 7.x linux on an i686 platform. The
> error looks like
>
> % make
> g77 -c -I/usr/local/netcdf35/include new.f
> g77 -o new -L/usr/local/netcdf35/lib -lnetcdf new.o
>
> new.o: In function `MAIN__':
> new.o(.text+0x17): undefined reference to `nf_open__'
> new.o(.text+0x31): undefined reference to `nf_inq_varid__'
> new.o(.text+0x4c): undefined reference to `nf_get_var_int2__'
> collect2: ld returned 1 exit status
> make: *** [new] Error 1
>
> Or, specifying the absolute path name for the library
>
> %make
> g77 -c -I/usr/local/netcdf35/include new.f
> g77 -o new new.o -l/usr/local/netcdf35/lib/libnetcdf.a
>
> /usr/bin/ld: cannot find -l/usr/local/netcdf35/lib/libnetcdf.a
> collect2: ld returned 1 exit status
> make: *** [new] Error 1
If you're giving the absolute path name for the library, you wouldn't
use the "-l" option, so the above should have been
g77 -o new new.o /usr/local/netcdf35/lib/libnetcdf.a
which I predict would result in the same undefined references you got
using "-L/usr/local/netcdf35/lib -lnetcdf".
> The install went well, with all tests on 'make test' successful. The
> library exists in the correct location:
One of the tests for 'make test' was linking and testing a Fortran-77
program. If you run that test again, you could see how the linking
was done. For example, on our Redhat Linux platform, part of the
output of 'make test' is:
...
Making `test' in directory /local/netcdf/src/nf_test
make[2]: Entering directory `/local/netcdf/src/nf_test'
+ /usr/bin/g77 -c -Wno-globals test_get.F
+ /usr/bin/g77 -c -Wno-globals test_put.F
+ /usr/bin/g77 -c -Wno-globals nf_error.F
+ /usr/bin/g77 -c -Wno-globals nf_test.F
+ /usr/bin/g77 -c -Wno-globals test_read.F
+ /usr/bin/g77 -c -Wno-globals test_write.F
+ /usr/bin/g77 -c -Wno-globals util.F
/usr/bin/gcc -c -O -Df2cFortran fortlib.c
/usr/bin/g77 -o nf_test -Wno-globals test_get.o test_put.o nf_error.o
nf_test.o test_read.o test_write.o util.o fortlib.o ../libsrc/libnetcdf.a -lm
...
You could switch to the nf_test directory and invoke 'make clean test'
to make sure this test worked. It's possible that it was never
attempted, because the 'configure' script couldn't find a working
Fortran compiler, in which case it would not try to build the Fortran
interface and the above test would have been skipped. The 'make test'
would still appear to succeed in that case in testing the C interface.
Make sure when you built netCDF that you defined the environment
variable
CPPFLAGS=-Df2cFortran
before running the configure script as the installation instructions
specify for Linux, gcc, and g77:
http://www.unidata.ucar.edu/packages/netcdf/INSTALL.html#linux
If you need to build over again, make sure you rm the "config.cache"
file and run "make clean" before setting your environment variables
and rerunning the 'configure' script. If it still doesn't work,
please send the information specified under "reporting problems" at:
http://www.unidata.ucar.edu/packages/netcdf/INSTALL.html#ReportingProblems
to "address@hidden" and we'll see if we can figure it out.
--Russ
_____________________________________________________________________
Russ Rew UCAR Unidata Program
address@hidden http://www.unidata.ucar.edu