[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[netCDF #LPX-911763]: problem compiling, undefined reference
- Subject: [netCDF #LPX-911763]: problem compiling, undefined reference
- Date: Mon, 11 Feb 2013 10:28:52 -0700
Hi Kensuke,
> I am rather a superficial user and I apologize if my description of
> the problem is lacking. I recently upgraded netcdf on my computer to
> version 4.2.1.1, and now I am having a problem compiling a program based
> on NoahLSM. It was working fine previously, but I cannot tell which
> version of netCDF I had before. The error message shows a long list of
> "undefined reference to..." example of which is pasted below:
>
> ifort -o driver.exe module_sf_noahlsm.o module_model_constants.o
> module_sf_urban.o kwm_date_utilities.o module_netcdf_io.o module_io.o
> module_ascii_io.o module_sfcdif_wrf.o module_Noahlsm_utility.o carb.o
> simple_driver.o -L/usr/local/lib -lnetcdff -lnetcdf
> module_netcdf_io.o: In function `initialize_netcdf_output':
> /home/ken/noahlsm-v3.3/simple_driver-v3.3/module_netcdf_io.f:41: undefined
> reference to `netcdf_mp_nf90_create_'
> /home/ken/noahlsm-v3.3/simple_driver-v3.3/module_netcdf_io.f:44: undefined
> reference to `netcdf_mp_nf90_def_dim_'
>
> I installed netcdf-fortran-4.2 but that did not solve the problem.
> I think I am using Intel Fortran Compiler for compiling noahLSM.
After building netcdf-fortran-4.2 and before installing it, did you run "make
check"?
Did it succeed with all its tests? If not, we'll need more information about
any
tests that didn't work.
If those tests worked and "make install" installed the netCDF library in
/usr/local/lib,
are you able to build one of the example Fortran programs from the source
distribution,
for example netcdf-fortran-4.2/examples/F77/simple_xy_wr.f ? To do this, it
will help
to look at the output of the nf-config program, that should have been installed
in
/usr/local/lib/bin/, if /usr/local/lib is where you installed netcdf-fortran.
In particular, look at the output of
nf-config --fflags --flibs
and try using that in your compile command. If the library was installed as
shared, but
you may also need to add the location of the shared library to your
LD_LIBRARY_PATH so
the run-time loader can find it.
As an example, I have the netcdf-4.2.1.1 C library installed in
/usr/local and I specified --prefix=/usr/local for where to install
the netcdf-fortran-4.2 libraries (--prefix=/usr/local/ is the default,
so I could have omitted it).
I then built the netCDF-fortran libraries with
LD_LIBRARY_PATH=/usr/local/lib LDFLAGS=-L/usr/local/lib
CPPFLAGS=-I/usr/local/include ./configure --prefix=/usr/local
Then I ran "make check" to make sure the library worked, and "make
install" to install the netcdf-fortran libraries in /usr/local.
Then the output of
/usr/local/bin/nf-config --fflags --flibs
was
-g -O2 -I/usr/local/include
-L/usr/local/lib -lnetcdff -L/usr/local/lib -lnetcdf -lnetcdf
(the extra -lnetcdf on the end is a harmless bug).
Then I compile the example program simple_xy_wr.f using those flags like this:
gfortran simple_xy_wr.f -o simple_xy_wr `/usr/local/bin/nf-config --fflags
--flibs`
Then I ran the resulting program, after setting the LD_LIBRARY_PATH to where
the libraries
were installed, because otherwise the operating system only looks in standard
places like
/usr/lib:
export LD_LIBRARY_PATH=/usr/local/lib
./simple_xy_wr
and the output was
*** SUCCESS writing example file simple_xy.nc!
--Russ
> My brief search told me to add -lnetcdff to the NETCDFLIB, but that did
> not solve the problem. The location of NETCDFLIB is correct, unless I
> am looking at a wrong file (user_build_options in noahLSM).
>
> Ken
>
>
Russ Rew UCAR Unidata Program
address@hidden http://www.unidata.ucar.edu
Ticket Details
===================
Ticket ID: LPX-911763
Department: Support netCDF
Priority: Normal
Status: Closed