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

[netCDF #LPX-911763]: problem compiling, undefined reference

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, 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 
Did it succeed with all its tests?  If not, we'll need more information about 
tests that didn't work.

If those tests worked and "make install" installed the netCDF library in 
are you able to build one of the example Fortran programs from the source 
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 
/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 
the run-time loader can find it.

As an example, I have the netcdf- 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


  -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 

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

   export LD_LIBRARY_PATH=/usr/local/lib 

and the output was

    *** SUCCESS writing example file simple_xy.nc!

> 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