Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)

Forgot password? | Forgot username? | Register

FMIKit Simulink failed to compile OpenModelica Source-FMU

FMIKit Simulink failed to compile OpenModelica Source-FMU

I'm currently facing problems when integrating a OpenModelica FMU into my Simulink model. Everything works fine if I import the FMU as binary. Both FMU for co-simulation and model exchange can be imported and simulated (FMI 2.0). Unfortunately I have to run the Simulink model on a realtime platform and therefore I need to use the source code of the FMU and compile the s-function myself.

I managed to compile the s-function by tweaking the Compiler #defines like -DFMI2_FUNCTION_PREFIX=myModel_, -DOMC_FMI_RUNTIME=1, -DCMINPACK_NO_DLL=1. The MinGW compiler that is shipped with Matlab outputs several warnings:


Compiling S-function sfun_Testmodel

Building with 'MinGW64 Compiler (C)'.
In file included from D:\Modelica\Testmodel\sources\Testmodel_FMU.c:55:0:
D:\Modelica\Testmodel\sources\fmi-export/ In function 'omc_assert_fmi_common':
D:\Modelica\Testmodel\sources\fmi-export/ warning: passing argument 1 of 'GC_vasprintf' from incompatible pointer type [-Wincompatible-pointer-types]
   GC_vasprintf(&str, msg, args);
In file included from D:\Modelica\Testmodel\sources\openmodelica_func.h:52:0,
                 from D:\Modelica\Testmodel\sources\Testmodel_FMU.c:10:
D:\Modelica\Testmodel\sources\util/modelica_string.h:71:5: note: expected 'const char **' but argument is of type 'char **'
int GC_vasprintf(const char **strp, const char *fmt, va_list ap);
In file included from D:\Modelica\Testmodel\sources\Testmodel_FMU.c:56:0:
D:\Modelica\Testmodel\sources\fmi-export/ In function 'FMI2CS_initializeSolverData':
D:\Modelica\Testmodel\sources\fmi-export/ warning: implicit declaration of function 'access' [-Wimplicit-function-declaration]
   if( access( flags_filename, 0 ) != -1 )

D:\Modelica\Testmodel\sources\util\ModelicaUtilities.c: In function 'ModelicaError':
D:\Modelica\Testmodel\sources\util\ModelicaUtilities.c:83:1: warning: 'noreturn' function does return
D:\Modelica\Testmodel\sources\util\ModelicaUtilities.c: In function 'ModelicaVFormatError':
D:\Modelica\Testmodel\sources\util\ModelicaUtilities.c:87:1: warning: 'noreturn' function does return
D:\Modelica\Testmodel\sources\util\ModelicaUtilities.c: In function 'ModelicaFormatError':
D:\Modelica\Testmodel\sources\util\ModelicaUtilities.c:94:1: warning: 'noreturn' function does return

D:\Modelica\Testmodel\sources\simulation\solver\initialization\initialization.c:77:12: warning: 'init_lambda_steps' initialized and declared 'extern'
extern int init_lambda_steps = 3;

MEX completed successfully.

When I start the model Matlab crashes without any signs.
I experience the same with Microsoft Visual C++ 2017 compiler. To get this compiler working I had to install the pthreads-win32 package and substitute strncasecmp() with the equivalent Windows implementation. Doing this I don't get any compiler warnings but Matlab crashes during model initialisation. Unlike MinGW there is the possibility to send a crash report with a stack trace.

Is this a bug with the exported source files? I thought that the source files inside the FMU should be able to be compiled without any dependencies (OMC Pull request 2989).  I'm using OpenModelica 1.18.0 with FMIKit Simulink 2.9 and Matlab 2018a.

Re: FMIKit Simulink failed to compile OpenModelica Source-FMU

Hi Andreas Th,

I have also had some problem when trying to integrate FMU from OM to a real-time test that require compilation from FMU-Source file. I dont have a direct solution to your problem, but maybe it will help. In my case, i had to recheck the modelDescription.xml to make sure all the necessary file are listed there, since in my case, the tool will read the xml file and goes from there. I also had to removed the defined "stopTime=1" in the xml file becaused it stoped my real-time test after 1s.

Like i've said, it might not be a solution to your problem but maybe it will give you some idea.

Re: FMIKit Simulink failed to compile OpenModelica Source-FMU

Hey AndreasTh,

It's correct that our modelDescription.xml doesn't contain all source files. We should fix this at some point. I've created a ticket for it: … ssues/8524

From your error messages it seems that the FMU is compiling fine. A few errors are normal (we should really fix them though...)
Problem seems to be executing the FMU binaries.

You could you try a few things:

1) Try out the nightly build of OpenModelica ( I recently fixed a bug where source files for source-code FMUs where missing. But since your model compiles fine that's probably not the solution. (If you get errors for undefined `_hybrid` set `NEED_CMINPACK=1`

2) Use logging from Matlab. There should be an option to log each fmi function call. Then we can get at least a rough idea where it crashes.

3) Try a different FMU importing tool to simulate the freshly compiled FMU. E.g. OMSimulator which comes with OpenModelica. I guess it is a FMU problem, but with that we can be sure.

4) You can try to run the FMI Importing tool with a debugger. To enable debugging for the generated FMU you need to have `-g` or even better `-g -O0` in your `CFLAGS` when compiling. Then run e.g. OMSimulator with gdb. Probably works with Matlab as well, but I never tried and having all of a GUI through gdb is extremely slow.


$ gdb OMSimulator
r myFMU.fmu

But you should open an issue on our GitHub about this:
If we can find the function (and line) that causes the issue we have a chance to fix it.
If your FMU is not a secret you can upload it to the issue as well. When it's not a Matlab issue I can run it through gdb.

There are 0 guests and 0 other users also viewing this topic
You are here: