-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compiling as shared library #50
Comments
…with OM, let us constinue the discussion in #50
I would recommend that @casella, @albertoleva and @fedetft have a look at the branch v4-dev and provide some feedback here. |
Tried building the v4-dev branch on Linux and testing with openmodelica, used these commands:
no issues found in the building step. Trying to run a model such as ExternalMedia.Test.CoolProp.CO2.TestStatesSatSubcritical however I still encountered two issues:
NOTE: to get the model to run I had to edit a few Modelica lines here and there, like "SI.IsothermalCompressibility > Modelica.SIunits.IsothermalCompressibility" probably because I'm using a different MSL than you,but I don't think this is the cause of the crash above. |
The crash problem was due to |
…with OM, let us constinue the discussion in #50
…with OM, let us constinue the discussion in #50
We need to handle the error functions in ExternalMedia. This is potentially a problem in case of dynamic linking, because the ModelicaError, ModelicaWarning (and in fact all ModelicaUtilities) functions may not be available inside the library when compiled as a dll/so. This issue was actually discussed some years ago in ModelicaSpecification #2191, but then the discussion got nowhere, probably for lack of strong end-user motivation / available time. @fedetftpolimi, who is a compiler and OS guru, figured out a very simple solution to that problem: you just need to export all the ModelicaUtilities symbols in the compiled simulation executable, and also in the Modelica compiler GUI, since ExternalMedia may be called at compile time as well, because of evaluation of package constants. This guarantees that the functions in the ExternalMedia dll can access them. This can be done both on Linux and Windows, and we know how to do that. However, this requires all tool vendors to agree to the principle and implement it in their tools, which is a bit of a lengthy process. In fact, Dymola does it on Linux, but apparently not on Windows, for some reason. We will start that discussion in #2191, but for the time being we figured a relatively simple hack that should work in all cases and does not require to change the structure of all ExternalMedia functions to have them return an error code string in case of trouble. The idea is that, at runtime, the first ExternalMedia function that is called is always a setState_XX function. There are only six of them. We just need to add a C wrapper function defined in the include annotation of the corresponding Modelica external functions, that passes to the actual library functions a pointer to ModelicaError. These C wrappers are statically compiled with the simulation code every time a model is generated, so they have access to that function and can pass the pointer further down the line. The first called setState_XX library function will then copy that pointer to a global static variable of the library, from which the errorMessage function will be able to retrieve it. In this way, all other external functions can be left unchanged, as they can safely call errorMessage, which will know what to do. We'll implement the new errorMessage handling next week, with a bit of luck we should finally get ExternalMedia to run on OMC as well. Since I'd like to have a MSL 3.2.3-compatible version that works in OMC to run legacy models using ExternalMedia, we have cherry-picked your changes regarding the shared library compilation, and then we'll release 3.3.2 and 4.0.0 based on that. |
We are almost done with that, see the dynamiclib branch. Only a clean-up of the build scripts needs to be performed |
Fix merged to master. |
I have tested the shared library compilation with Dymola 2022x on Windows. That seems to work fine. However, could any of you OM guys take over from here? I would be happy to help with CMake etc, but I am not familiar with OpenModelica at all...
The text was updated successfully, but these errors were encountered: