Giving additional resource(.so file) to an s-function and generate FMU

9 vues (au cours des 30 derniers jours)
Mayur
Mayur le 5 Août 2025
Commenté : Mayur le 14 Août 2025
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
Meg Noah
Meg Noah le 5 Août 2025
Did you try 'addpath' to add the path of the .so file?
Mayur
Mayur le 6 Août 2025
Thanks @Meg Noah for your suggestion.
Yes. It works for running the sfunction. After that I am generating FMU and it fails to find the file while running the FMU. Also, manually copying the file inside FMU doesn't help

Connectez-vous pour commenter.

Réponses (1)

Arushi
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
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.
Mayur
Mayur le 14 Août 2025
Hi,
The 2021b version has a limitation to add additonal resources.
Also, check this dialog box in the attached image.

Connectez-vous pour commenter.

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!

Translated by