Page tree

GRIB-API support is being discontinued at the end of 2018. Please consider upgrading to ecCodes

Skip to end of metadata
Go to start of metadata


From release 1.13.0 onwards, GRIB API can also use CMake for compilation and installation. This is a first step towards an homogenisation of the installation procedures for all ECMWF packages.

Like autotools, CMake will run some tests on the user's system to find out if required third-party software libraries are available and note their locations (paths). Based on this information it will produce the Makefiles needed to compile and install GRIB API.

CMake is a cross-platform free software program for managing the build process of software using a compiler-independent method.

Generating the Makefiles with CMake

One nice and highly recommended feature of CMake is the ability to do out of source builds. In this way you can make all your ".o" files, various temporary depend files, and even the binary executables without cluttering up your source tree. To use out of source builds, first create a build directory, then change into your build directory and run cmake pointing it to the source directory and using your own options.

The command gives feedback on what requirements are fulfilled and what software is still required. The following table gives an overview of the different options.  The default (without any options) will compile a shared library only and install it in /usr/local/.


CMAKE_INSTALL_PREFIXwhere you want to install your GRIB API/usr/local

Select the type of compilation:

  • Debug
  • RelWithDebInfo
  • Release
  • Production
BUILD_SHARED_LIBSSelect the type of library built:
  • ON (Build shared libraries only)
  • OFF (Build static libraries only)
  • BOTH (Build both shared and static libraries)
ENABLE_NETCDFFor the grib to netcdf convert toolAUTO
ENABLE_JPGEnable JPEG2000 support. This option should look for Jasper or OpenJPG
(OpenJPEG only supported up to version 1.5.2)


ENABLE_PNGEnable PNG support for decoding/encodingOFF
ENABLE_PYTHONOffers the Python interface to the packageAUTO
ENABLE_FORTRANOffers the Fortran interface to the packageAUTO
cmake options

The C and Fortran compilers are chosen by CMake. (This can be overridden by setting the environment variables CC and FC to the preferred compiler). Further the variables CMAKE_C_FLAGS or CMAKE_Fortran_FLAGS can be used to set compiler flags for optimisation or debugging.

Note: To see the full output from the compilation, you can use:

   make VERBOSE=1

Quick installation guide

Here is an example of a list of commands you could use to install GRIB API.  It is assumed “>” is the shell prompt. The version number may vary.

> tar -xzf  grib_api-1.14.0-Source.tar.gz

> mkdir build ; cd build

> cmake  ../grib_api-1.14.0-Source  -DCMAKE_INSTALL_PREFIX=/path/to/where/you/install/gribapi


> make

> ctest

> make install

Note: On a machine with multiple cores, compilation will be faster by specifying the number of cores to be used simultaneously for the build, for example:

  make -j4
ctest -j4


It is recommended that you always build in a clean directory and also install into a clean directory.


  • No labels