Giving additional resource(.so file) to an s-function and generate FMU
이전 댓글 표시
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?
답변 (1개)
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
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.
Mayur
2025년 8월 14일
카테고리
도움말 센터 및 File Exchange에서 FMU Importing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!