CATIA-Systems / FMIKit-Simulink

Import and export Functional Mock-up Units with Simulink
Other
155 stars 50 forks source link

Source code FMUs lead to "unresolved reference" errors if they are statically linked #392

Open IZacharias opened 1 year ago

IZacharias commented 1 year ago

If an FMU contains source code and is statically linked, the FMI function names should be prefixed with the modelIdentifier. To achieve this, the FMI3_FUNCTION_PREFIX macro must be defined before the #include "fmi3Functions.h". Source Code FMUs 3.0 that are generated with the FMI Kit for Simulink define the macro too late. Code snippet from fmi3Functions.c:

#include "fmi3Functions.h"

#include <float.h>  /* for DBL_EPSILON, FLT_MAX */
#include <math.h>   /* for fabs() */
#include <string.h> /* for strdup() */
#include <stdarg.h> /* for va_list */
#include <stdio.h>  /* for vsnprintf(), vprintf() */

#include "fmiwrapper.inc"

The macro FMI3_FUNCTION_PREFIX is defined in fmiwrapper.inc

#ifndef NO_FMI_FUNCTION_PREFIX
#define FMI3_FUNCTION_PREFIX times2_
#endif

That is, the prefix is not used for building the function names. As a result, the FMU cannot be used in a simulation environment that provides a fmi3Functions.h file that constructs the function names with FMI3_FUNCTION_PREFIX as described in the FMI 3.0 specification.