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

9 次查看(过去 30 天)
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 个评论
Mayur
Mayur 2025-8-6
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

请先登录,再进行评论。

回答(1 个)

Arushi
Arushi 2025-8-8
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 个评论
Arushi
Arushi 2025-8-14
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Deploy Standalone Applications 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by