Giving additional resource(.so file) to an s-function and generate FMU
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am generating FMU from a matlab s-function. The s-function needs an additional resource (.so file) to run and this is made available in the current path. No reference or definition given in s-function for this additional resource( I don't know how to give)
Issue: The FMU runs only when the additional resource (.so file) is in the current path else Matlab crashes. I want to run the FMU by having this additional resouce (.so file) inside FMU so that it can run on another PC. I tried creating a "resources/filename.so" inside MyModel.fmu unfortunately it doesn't helps.
Any thoughts?
2 commentaires
Réponses (1)
Arushi
le 8 Août 2025
Hi Mayur,
If your S-function depends on a .so file and you're trying to generate a portable FMU that works across different machines, here's what worked best for me:
- Include the .so file in the resources/ folder when exporting the FMU.
- Modify your S-function C/C++ code to dynamically load the .so using dlopen() with the full path.
void* handle = dlopen("myLibrary.so", RTLD_NOW);
- At runtime, the FMU is automatically extracted to a temporary directory. You can build the path to the .so file like this:
char path[PATH_MAX];
sprintf(path, "%s/resources/myLibrary.so", modelResourcePath);
void* handle = dlopen(path, RTLD_NOW);
modelResourcePath can be obtained from the FMU runtime or passed in using the FMI callback functions, depending on your setup.
This approach makes the FMU completely self-contained and portable.
Hope this helps!
3 commentaires
Arushi
le 14 Août 2025
Hi Mayur,
Since you’re on MATLAB R2021b, you can use the built-in Additional Files option when exporting the FMU to include your .so dependency directly inside the FMU package. This removes the need to unzip/re-zip the FMU manually.
In the “Additional Files” section of the export dialog, you can specify:
- binaries/<arch>/ for dependent libraries loaded automatically by the FMU binary, or
- resources/ for files you plan to load manually (e.g. dlopen in your S-Function).
Once you add your .so here and adjust your S-Function to build the absolute path at runtime, your FMU should run without needing the .so in the working directory.
Voir également
Catégories
En savoir plus sur Deploy Standalone Applications dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!