FMI4cpp is a brand new FMI 2.0 implementation for C++.  It has been written from the ground up in modern C++. The API is very similar to FMI4j.

All dependencies are available through vcpkg.

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

using namespace fmi4cpp::fmi2;

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

int main() {

    import::Fmu fmu("path/to/fmu.fmu");
    auto slave = fmu.asCoSimulationFmu().newInstance();

    auto md = slave->getModelDescription();    
    auto var = md.getVariableByName("myVar").asReal();

    double t;
    double value;
    while ( (t = slave->getSimulationTime()) <= stop) {
        if (slave->doStep(stepSize)!= fmi2OK) {

        if (var->read(*slave, value) != fmi2OK) {
        std::cout << << "=" << value << std::endl;

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.