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

[netCDF #LEX-922145]: confusion



Xuesheng,

> Thanks for reply. How to add
> 
> **-lnetcdff ?

Assume you have a Fortran application, for example the program simple_xy_wr.f90,
available from here:

  http://www.unidata.ucar.edu/software/netcdf/examples/programs/simple_xy_wr.f90

that calls netCDF library functions.  To compile it and link it to the netCDF 
library you have installed, you would use something like

  % gfortran -I/usr/local/include simple_xy_wr.f90 -o simple_xy_wr 
-L/usr/local/lib -lnetcdff

but instead of "/usr/local" you would use the path where you installed the 
library.

That would result in the executable program simple_xy_wr.  But if you just try 
to run it
without setting the run-time library path, you will probably get an error like 
this:

  % ./simple_xy_wr
  ./simple_xy_wr: error while loading shared libraries: libnetcdff.so.0: cannot 
open shared object file: No such file or directory

If you first set the environment variable LD_LIBRARY_PATH to include the 
directory where
the library file is installed, things will work.  Since you're using csh, this 
would be
done with

  % setenv LD_LIBRARY_PATH 
/hou_proj2/EM_projects/xyu/Ov2-deps/lib:$LD_LIBRARY_PATH

Then the run-time loader will know to look in that directory for libraries, and 
running
the program will work:

  % ./simple_xy_wr
   *** SUCCESS writing example file simple_xy.nc!

You could set LD_LIBRARY_PATH in your .cshrc file so it would automatically get 
set
every time you log in.

If instead you want to store the library path with the file, so that you don't 
have to
worry about LD_LIBRARY_PATH and so that other users can use your program 
without having
to set any environment variables, you can either install it somewhere that is 
always
searched by default for run-time libraries (for example /usr/lib), or you can 
use 
additional flags when compiling/linking to store that information with the file:

  % gfortran -I/usr/local/include simple_xy_wr.f90 -o simple_xy_wr 
-L/usr/local/lib -lnetcdff -Wl,-rpath -Wl,/usr/local/lib

  % ./simple_xy_wr
   *** SUCCESS writing example file simple_xy.nc!

where again, instead of "/usr/local" you would use your installation location 
"/hou_proj2/EM_projects/xyu/Ov2-deps".

> The help page also says
> 
> to link Fortran software with the installed Fortran library, You could also
> use the "nf-config" utility installed in *{DIR1}*/bin.
> 
> How to use this "nf-config"?

The nf-config program helps you compile by providing the necessary compile 
flags,
link flags, and directories.  Here's how you could use it to compile and link an
application:

  gfortran simple_xy_wr.f90 -o simple_xy_wr `nf-config --fflags --flibs`

However, it doesn't set LD_LIBRARY_PATH for you or provide the extra options 
needed 
to store the runtime linker information about where the shared libraries are 
installed.

--Russ

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



Ticket Details
===================
Ticket ID: LEX-922145
Department: Support netCDF
Priority: Normal
Status: Closed