OpenModelica
OpenModelica copied to clipboard
Bug in CMAKE leads to FMU export with missing dependency
From the discussion in #11604, it seems that there is a CMAKE bug that leads to missing dependencies in FMUs if using clang (not if using gcc).
@bilderbuchi notes:
This comment in the cmake issue tracker sounds quite relevant, and could be the root cause, and an easy fix (tabs vs spaces). I guess that should be tracked a separate cmake issue, but I don't have an account there. Anybody? Can we work around that somehow in the meantime, e.g. with some sed invocation in-between, or somesuch?
I would suggest to implement his proposed workarund and, if possible, to open a ticket on the CMAKE tracker addressing this issue.
For now I have fixed this in our OMDev repos via: https://gitlab.liu.se/OpenModelica/OMDev/-/commit/e1bb0576bfb1ebb4c63fbbcc6e37fb825da16ac9 and this: https://gitlab.liu.se/OpenModelica/OMDevUCRT/-/commit/1c8bc4a63fddecee1860961381b1c731e4acd991
It seems to be working. I will try to make a PR for CMake.
This fix will end up in v1.22.3 and of course the nightly.
Opened a PR with cmake: https://gitlab.kitware.com/cmake/cmake/-/merge_requests/9325
@adrpo shall we close this?
Yes, my PR to cmake was merged: https://gitlab.kitware.com/cmake/cmake/-/merge_requests/9325
On the today (12-3-2024) nightly build I have tested FMU export with clang. Their size is 280 kb (with euler explicit), so I suppose that is not working. It is implemented on the current nightly?
Update: The same error appears on third party simulator when try to simulate (see details in #11604)
@adrpo maybe something is missing to get the OMDev changes into the nightly? Some submodule update?
Update: Using today (15-3-2024) build: FMU now has 459 KB, so there is a difference between previous versions, but the erorr in third party software is the same when try to simulate (see details in #11604):
@BasilioPV the FMU size isn't a good indicator. You can use tools like Dependencies too check why the DLL can't be loaded. Unzip the FMU and open FMU/binaries/win64/Test_FMU.dll with Dependencies and add the error message here. And tell us what's inside the binaries/win64 directory.
Besides the CVODE linking issue (we are linking statically now, so it should work and the increased size suggest it did) there should be some sort of pthreads DLL. If Dependencies doesn't show any errors it's probably an issue with the importing tool missing to call SetDllDirectoryA before calling LoadLibraryA, see https://github.com/OpenModelica/OMSimulator-3rdParty/commit/ca418d7768c036ac15e9894d7f00d2118b3399a6.
We are in the process of updating OMSimulator to handle this.
Thanks for pointing to Dependencies tool!!
FMU, with clang and CVODE and explicit Euler :
That's looking good. Please open an issue with the FMU importing tool you use so that they'll add SetDllDirectoryA before loading the DLL. As far as I know there is no Windows equivalent to setting RPATH on Unix, so we can't tell Windows where to look for libwinpthread-1.dll.
Ah sorry, I misread the output from your image. Did you copy Test_FMU.dll out of FMU/binaries/win64? The location matters and there should be libwinpthread-1.dll in the same directory.
There are only these two files in the directory:
Tested with both in the same directory, with the same result:
Any ideas on this?
Can't reproduce with OpenModelica v1.23.0-dev-416-g0f1ee9aef5 (64-bit) on my Windows 11 or a clean Windows 11 virtual machine. libwinpthread-1.dll is in the binaries directory and Dependencies reports no load errors.
@BasilioPV do you also see libwinphtread-1.dll in the binaries directory?
I have installed the today's OMedit (v1.23.0-dev-420-g1cb1c69e62) (64-bit) On Simulation, this is configured:
On FMI:
And the Modelica model to export is:
model Test_FMU parameter Real A=2; output Real B; equation B=A*time; end Test_FMU;
And there is no libwinphtread-1.dll in the binaries:
My computer is Windows 10 Pro.
I tried again with the settings from your screenshot and here's the resulting FMU: Test_FMU.zip
The only things I can think of are some settings in OMEdit we aren't aware of or some difference between the software on Windows 10 and Windows 11. I don't have access to a Windows 10 VM, so I can't try that.
@BasilioPV I have Windows 10, I tried to export your MWE and this is the content of binaries/win64
I would suggest you to reset the OMEdit options. Maybe there is some setting you made somewhere that break this.
Thanks @casella , there are settings that persist after an uninstall + install a new version? How to remove them?
All of them are kept, settings are saved in some file or register key. You can reset them to factory settings with Tools | Options | Reset button, then close and restart OMEdit.
Ok, after reset, the MSL 4.0.0 is loaded by default.
Now this translation error is shown:
[3] 07:58:53 Translation Error [Test_FMU: 2:3-2:19]: Parameter A has neither value nor start value, and is fixed during initialization (fixed=true).
That I solve by putting the value:
parameter Real A=0;
But the result remains the same:
I have tried now with a clean W10 on a virtual machine (virtualbox). After install the latest nightly build and change only:
The result still the same:
NOTE: If I don't change anything, with OMedit out-of-the-box, the result remains the same, no libwinpthread-1.dll
@AnHeuermann where is the libwinpthread-1.dll fetched from? Maybe it's missing on @BasilioPV's computer?
On a clean W10 virtual machine, after installing OM nightly build, it is placed at:
As @BasilioPV showed it's installed together with OpenModelica in C:\Program Files\OpenModelica1.23.0-dev-64bit\tools\msys\ucrt64\bin.
You have OMDev installed. Maybe that's the issue somehow? It also has pthreads and CMake available. But it seems to be the correct ucrt version. Also the git directory is in you PATH. That can lead to incompatibilities between UCRT and MINGW.
In fact, I don't have OMDev installed, and it works for me.
I will start again the process. On a clean W10 VM:
Before install, I don't have the file in the PC:
After Install OM nightly build (of today):
Now I open OMedit, load Test_FMU:
And directly right click and export to FMU:
Now I test changing only "Explicit Euler" to "CVODE" on FMU export settings:
Still the same. What I'm doing wrong?
@AnHeuermann maybe exporting to source code FMU and manually building it can give some idea?
This is a very odd.
Now I test changing only "Explicit Euler" to "CVODE" on FMU export settings:
@BasilioPV do you mean it works if you export with Euler?