esio  0.1.9
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Linking applications

Compiling and linking a C/C++ application against ESIO

To compile and link a C or C++ application against your ESIO installation, the installation's include directory and lib directory must be added to your C/C++ compiler's include and library search paths, respectively. You will need to supply flags to link against ESIO and HDF5's basic and high-level libraries. Note that you will either need to use your MPI implementation's C/C++ compiler wrapper script, denoted here by $(MPICC), or you will additionally need to provide MPI-related flags within the sample commands below.

This tutorial assumes you installed HDF5 under $HDF5HOME and also that at ESIO configuration time you specified –prefix=$HOME to install ESIO under your home directory (It may be necessary to include your home directory under in

LD_LIBRARY_PATH

). In this case, compiling and linking an MPI application consisting of a single source file named app.c might look as follows:

> $(MPICC) -I$HOME/include app.c -L$HOME/lib -lesio -L$HDF5HOME -lhdf5_hl -lhdf5 -lz -lm

This is error prone as you must supply the same HDF5 installation directories used at ESIO configuration time. Continuing the example, if you set your PKG_CONFIG_PATH environment variable to contain $HOME/lib/pkgconfig you can use pkg-config to lookup the relevant linking information automatically:

> $(MPICC) `pkg-config --cflags esio-hdf5` app.c `pkg-config --libs esio-hdf5`

Finally, if you are using HDF5's parallel compiler wrapper script h5pcc the above two examples no longer need to include many HDF5-related specifics:

> h5pcc -I$HOME/include app.c -L$HOME/lib -lesio
> h5pcc `pkg-config --cflags esio` app.c `pkg-config --libs esio`

Using pkg-config will avoid many easy-to-make mistakes. It is highly recommended you use pkg-config with ESIO where possible.

Compiling and linking a Fortran application against ESIO

To compile and link a Fortran 90 application against your ESIO installation, the installation's lib directory must be added to both your Fortran compiler's include and library search paths. In particular, if you do not provide lib within the search path you will see error messages stating that esio.mod is missing. You will need to supply flags to link against ESIO's Fortran library (esiof) and HDF5's basic and high-level C libraries (hdf5 and hdf5_hl). The HDF5 Fortran libraries (hdf5_fortran and hdf5hl_fortran) are not required. You do not need to have built HDF5 with Fortran support enabled.

Note that you will either need to use your MPI implementation's Fortran compiler wrapper script, denoted here by $(MPIFC), or you will additionally need to provide MPI-related flags within the sample commands below.

Assuming the same installation detailed in the C/C++ examples just above, you would compile and link a Fortran MPI application consisting of a single source file named app.F90 as follows:

> $(MPIFC) -I$HOME/lib app.F90 -L$HOME/lib -lesiof -L$HDF5HOME -lhdf5_hl -lhdf5 -lz -lm

Using pkg-config simplifies the process considerably:

> $(MPIFC) `pkg-config --variable=fflags esio-hdf5` app.F90 `pkg-config --variable=flibs esio-hdf5`

Again, if you are using HDF5's parallel compiler wrapper script h5pfc the above two examples become simpler:

> h5pfc -I$HOME/lib app.F90 -L$HOME/lib -lesiof
> h5pfc `pkg-config --variable=fflags esio` app.F90 `pkg-config --variable=flibs esio`

Important Note: F90 module file formats are not consistent across multiple compilers. Therefore, a Fortran application and the ESIO F90 interface must be built with the same Fortran compiler family to ensure compatibility.

Obtaining ESIO configuration information from pkg-config

ESIO's pkg-config files capture many configuration-time settings so that they can be retrieved easily. For example, the MPI and HDF5 compiler wrapper scripts used to build an ESIO installation can be retrieved as follows:

> pkg-config --variable=mpicc esio-hdf5
> pkg-config --variable=hdf5_version esio-hdf5
> pkg-config --variable=h5pcc esio-hdf5

These values could be used, for example, in a standalone Makefile. Provided that your PKG_CONFIG_PATH is configured correctly, such a Makefile can automatically determine the information necessary to build an ESIO-based application.

Using ESIO with GNU Autoconf/Automake

Because an ESIO installation provides pkg-config information, using ESIO with Autoconf and Automake in a C/C++ project is straightforward. The exact details are beyond the scope of this documentation, but the process consists of the following steps:

  1. Use AX_MPI within your configure.ac to determine where your system's MPI compiler wrappers are located.
  2. Ensure that automake is using the MPI compiler wrapper by including a statement like CC=@MPICC@ within your Makefile.am.
  3. Use the PKG_CHECK_MODULES autoconf macro to look for ESIO's esio-hdf5 pkg-config information at configure time. Load the information into variables like ESIO_CFLAGS and ESIO_LIBS.
  4. Add ESIO_CFLAGS and ESIO_LIBS to the appropriate targets within your Makefile.am.

One very good, but not ESIO-specific, write up on using GNU Autoconf/Automake with pkg-config is Using C/C++ libraries with Automake and Autoconf.


Generated on Thu Jan 16 2014 10:16:33 for esio by  doxygen 1.8.2