Using the IMAS Cpp

Making the IMAS Cpp available for use

When you’re working with a local installation, you can source the installed environment file:

Set environment variables (replace <install_dir> with the folder of your local install)
source <install_dir>/bin/al_env.sh

Using the Access Layer with your C++ program

The following example program will load the C++ interface to the Access Layer to print the version of the access layer and data dictionary.

imas_hello_world.cpp
// Include the Access Layer
#include "ALClasses.h"
#include <iostream>

// The Access Layer declares types in the IdsNs namespace. For brevity of
// examples we will use it here, even though it is considered bad practice:
// https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice
using namespace IdsNs;

int main(int argc, char *argv[]) {
    std::cout << "Hello world!" << std::endl;
    std::cout << "Access Layer version info:" << std::endl;
    std::cout << "  Low level version: " << getALVersion() << std::endl;
    std::cout << "  Data Dictionary version: " << al_dd_version << std::endl;
    std::cout << "  C++ HLI version: " << al_cpp_version << std::endl;

    return 0;
}

If you save this as a file imas_hello_world.cpp, you can compile it as follows:

g++ imas_hello_world.cpp `pkg-config --libs --cflags imas-cpp` -pthread -o imas_hello_world

We use pkg-config to output the required libraries and compiler flags to use the C++ Access Layer. Feel free to use a different compiler than gcc, and/or add additional compilation flags to your liking.

Note

Compilation and linking flags for the IMAS-Cpp library can simply be obtained with the following pkg-config names:

  • imas-cpp (or al-cpp for compatibility with versions < 5.6) for the data access library (definition of IDS objects, I/O functions, etc…)

  • imas-identifiers-cpp (or al-identifiers-cpp) for the identifiers library

When the compilation is successful, a program imas_hello_world was compiled for you. When you execute it, the result is:

$ ./imas_hello_world
Hello world!
Access Layer version info:
  Low level version: 5.0.0
  Data Dictionary version: 3.39.0
  C++ HLI version: 5.0.0

Congratulations if this runs successfully! You have included the C++ Access Layer successfully in a program. In the next sections of the documentation you can see how to: