Next: , Previous: Using, Up: Using


4.1 Using Linker Flags with NetCDF

For this to work, you have to tell the linker which libraries to link to (with the -l option), and where to find them (with the -L option).

Use the -L option to your linker to pass the directories in which netCDF, HDF5, and zlib are installed.

Use the -l (lower-case L) option to list the libraries, which must be listed in the correct order:

     -lnetcdf -lhdf5_hl -lhdf5 -lz -lm

If szip was used when building HDF5, you must also use -lsz.

On some systems you must also include -lm for the math library.

If HDF4 was used when building netCDF, you must also use -lmfhdf -ldf -ljpeg.

Finally, if you use the parallel-netcdf library, you must use -lpnetcdf.

The worst case scenario is, using all of the above libraries:

     -lnetcdf -lpnetcdf -lmfhdf -ldf -ljpeg -lhdf5_hl -lhdf5 -lz -lsz -lm

In such a case one also needs to provide the locations of the libraries, with the -L flag. If libraries are installed in the same directory, this is easier.

Use the nc-config to learn the exact flags needed on your system (see nc-config).