Skip to content
FMI 2.0 implementation written in modern C++.
Branch: master
Clone or download
markaren Merge pull request #67 from NTNU-IHB/fix/42-canBeInstantiatedOnlyOnce…

Fix/42 can be instantiated_only_once_per_process handling
Latest commit 5ba6137 Jun 13, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
cmake link openssl on unix if available May 25, 2019
include/fmi4cpp use boost/optional in public headers Apr 16, 2019
resources/fmus/2.0 add me Test-FMUs Mar 15, 2019
src Merge pull request #67 from NTNU-IHB/fix/42-canBeInstantiatedOnlyOnce… Jun 13, 2019
tool snake_case and rename function Mar 27, 2019
.gitignore update gitignore Jan 9, 2019 mostly done refactoring Mar 21, 2019
CMakeLists.txt update logging Mar 23, 2019 mostly done refactoring Mar 21, 2019
LICENSE update license Sep 19, 2018 Fix another error in the README code [skip ci] May 29, 2019
azure-pipelines.yml re-enable curl on azure vcpkg May 25, 2019
run_conan_install.bat add conan install script for windows Mar 13, 2019 Update conan stuff Feb 13, 2019

FMI4cpp (work in progress)

License: MIT contributions welcome Join the chat at

CircleCI Build status

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 it provides a clean, easy to use API and is easy to install (through vcpkg). It perform just as good as FMI Library, provides more features and is significantly easier to both build and use.

Install instructions

Refer to

Build instructions

Refer to


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

using namespace std;
using namespace fmi4cpp;

const double stop = ...;
const double stepSize = ...;

int main() {

    fmi2::fmu fmu("path/to/fmu.fmu");
    // or (with -DFMI4CPP_WITH_CURL=ON)
    // auto fmu = fmi2::fmu::from_url("")
    auto cs_fmu = fmu.as_cs_fmu();
    auto me_fmu = fmu.as_me_fmu();
    auto cs_md = cs_fmu->get_model_description(); //smart pointer to a cs_model_description instance
    cout << "model_identifier=" << cs_md->model_identifier << endl;
    auto me_md = me_fmu->get_model_description(); //smart pointer to a me_model_description instance
    cout << "model_identifier=" << me_md->model_identifier << endl;
    auto var = cs_md->get_variable_by_name("my_var").asReal();
    cout << "Name=" << <<  ", start=" << var.start().value_or(0) << endl;
    auto slave = cs_fmu->new_instance();
    // or (with -DFMI4CPP_WITH_ODEINT=ON)
    // auto solver = make_solver<rk4_classic_solver>(1E-3);
    // auto slave = me_fmu->new_instance(solver);
    double t;
    double value;
    while ( (t = slave->get_simulation_time()) <= stop) {

        if (!slave->step(stepSize)) {
            cerr << "Error! step() returned with status: " << to_string(slave->last_status()) << endl;
        if (!*slave, value)) {
            cerr << "Error! step() returned with status: " << to_string(slave->last_status()) << endl;
        cout << "t=" << t << ", " << << "=" << value << endl;
    return 0;


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.
  --me                   Treat FMU as an Model Exchange FMU.
  -v [ --variables ] arg Variables to print.
You can’t perform that action at this time.