Procedure to build NetCDF

  1. Create build and install locations, and set them using the environment variables build_dir and install_dir, for example:

    mkdir netcdf_build
    mkdir netcdf_install
    export build_dir=/path/to/netcdf_build
    export install_dir=/path/to/netcdf_install

    replacing /path/to/ with the path to the new directories.

  2. Specify the location of HDF5 and (optionally) Parallel NetCDF installations by setting hdf_dir, and (optionally) pnetcdf_dir, such as:

    export hdf_dir=/path/to/hdf5_install
    export pnetcdf_dir=/path/to/pnetcdf_install

    replacing /path/to/hdf_install and /path/to/pnetcdf_install  with the paths to your HDF5 and (optionally) Parallel NetCDF installations, respectively.

  3. Download and unpack NetCDF:

    cd $build_dir
    tar -zxvf netcdf-4.7.0.tar.gz
    cd netcdf-4.7.0
  4. To build for Arm AArch64, you require up-to-date versions of config.guess and config.sub.

    To obtain up-to-date versions, use:

    wget ';a=blob_plain;f=config.guess;hb=HEAD' -O bin/config.guess
    wget ';a=blob_plain;f=config.sub;hb=HEAD' -O bin/config.sub
  5. Set the compiler environment variables:

    export CC=mpicc
    export CXX=mpicxx
    export F77=mpif77
    export FC=mpif90
    export MPICC=mpicc
    export MPIFC=mpifc
    export MPICXX=mpicxx
  6. Configure the build by passing the location of the HDF5 and (optionally) Parallel NetCDF include and lib directories through CPPFLAGS and LDFLAGS, respectively:

     ./configure --prefix=$install_dir CPPFLAGS="-I$hdf5_dir/include -I$pnetcdf_dir/include -I$zlib_dir/include" CFLAGS="-DHAVE_STRDUP -O3 -mcpu=native" LDFLAGS="-L$hdf5_dir/lib -L$pnetcdf_dir/lib -L$zlib_dir/lib" --enable-pnetcdf  --enable-parallel-tests --enable-shared --enable-netcdf-4  --with-pic --disable-doxygen  

    Note: The Parallel NetCDF library and the --enable-pnetcdf flag are optional and are only required for parallel access to older NetCDF data files (pre-version 4).

  7. Make some minor changes to the default flags in libtool:

    sed -i -e 's#wl=""#wl="-Wl,"#g' libtool
    sed -i -e 's#pic_flag=""#pic_flag=" -fPIC -DPIC"#g' libtool
  8. Build and install NetCDF, using:

    make -j
    make check
    make install
Previous Next