FMI 2.0 implementation written in modern C++.
Switch branches/tags
Clone or download
Lars Ivar Hatledal
Latest commit 34cf35c Dec 10, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
cmake remove sundials references Nov 1, 2018
examples update path to test FMUs Nov 28, 2018
include/fmi4cpp Fix compilation under linux Dec 10, 2018
src fix getOs() returning win32 on win64 Dec 10, 2018
tests update path to test FMUs Nov 28, 2018
tool Update driver and crosschecker Dec 10, 2018
.gitignore update gitignore Aug 30, 2018
CMakeLists.txt suppress warning appearing in boost headers under MSVC Dec 10, 2018
LICENSE update license Sep 19, 2018 Update readme Dec 6, 2018

FMI4cpp (work in progress)

FMI4cpp is a cross-platform FMI 2.0 implementation written in modern C++.

Influenced by it's spiritual brother FMI4j, it aims to be an easy to install, easy to use, object oriented and fast FMI implementation for C++.

FMI4cpp supports both Co-simulation and Model Exchange.
For Model Exchange, solvers from odeint can be used.

Why should I use this over other C/C++ FMI Libraries

Because this library provides a clean, easy to use API and is easy to install (through vcpkg).

How do I use it in my own project?

Recommended way is to install vcpkg and run:

./vcpkg install fmi4cpp

The alternative is to fetch the dependencies manually, put them in the path somewhere and run the regular CMake install procedures.

Development dependencies

Install vcpkg and run:

./vcpkg install boost-property-tree boost-ublas boost-odeint boost-program-options libzip

Then tell CMake about your vcpkg installation by passing
-DCMAKE_TOOLCHAIN_FILE=C:\vcpkg\scripts\buildsystems\vcpkg.cmake to it.

Note that boost-ublas and boost-odeint are optional and can be omitted by passing -DFMI4CPP_WITH_ODEINT=OFF to CMake. Similarly, boost-program-options can be omitted by passing -DFMI4CPP_BUILD_TOOL=OFF.

On linux you might need to install some additional libraries, which are required by libzip:

./vcpkg install bzip2 openssl

On *NIX systems the dependencies can of course be installed using the native package handler.


#include <iostream>
#include <fmi4cpp/fmi2/fmi4cpp.hpp>

using namespace fmi4cpp::fmi2;

const double stop = 10.0;
const double stepSize = 1.0/100;

int main() {

    auto fmu = Fmu("path/to/fmu.fmu").asCoSimulationFmu();
    auto md = fmu->getModelDescription();
    std::cout << "modelIdentifier=" << md->modelIdentifier() << std::endl;
    auto var = md->getVariableByName("my_var").asRealVariable();
    cout << "Name=" << << ", start=" var.start().value_or(0) << endl;
    auto slave = fmu->newInstance();
    double t;
    double value;
    while ( (t = slave->getSimulationTime()) <= stop) {

        if (!slave->doStep(stepSize)) {
            //error handling
        if (!*slave, value)) {
            //error handling
        std::cout << "t=" << t << ", " << << "=" << value << std::endl;


FMI4cpp comes with a simple CLI for testing FMUs, called fmu_driver.

  -h [ --help ]          Print this help message and quits.
  -f [ --fmu ] arg       Path to FMU.
  -o [ --output ] arg    Where to store the generated CSV results.
  --start arg            Start time.
  --stop arg             Stop time.
  --stepsize arg         StepSize.
  -v [ --variables ] arg Variables to print.

Running examples/tests

In order to run the example/test code, a system variable named TEST_FMUs must be present on your system. This variable should point to the location of the content found here.

The examples are built by default. To change this pass -DFMI4CPP_BUILD_EXAMPLES=OFF to CMake. Test are on the other hand not built by default. To change this pass -DFMI4CPP_BUILD_TESTS=ON to CMake.

To run the tests you will need an additional dependency:

./vcpkg install boost-test