Problem importing a static/dynamic library (.a/.so files) to build a Simulink model on the Speedgoat

16 visualizzazioni (ultimi 30 giorni)
Hi, I would like to import a C library in my Simulink model, in order to build it on a Speedgoat target (x86_64 Linux/QNX).
I have already tested the model with a .lib static library file on my target windows machine and everything works as it should.
But whenever I import the Linux lib files (.a static library or .so dynamic) it failes to build the model with LINK error as "Invalid or corrupted file" or "Cannot open file"
Am I missing something ?
Thanks in advance for your help

Risposte (1)

akshatsood
akshatsood il 19 Mar 2024
Modificato: akshatsood il 19 Mar 2024
I see that you are encountering problems while importing static (.a) or dynamic (.so) libraries to build a Simulink model on a Speedgoat real-time target machine. The process generally involves ensuring that your library is compatible with the Speedgoat's real-time operating system, linking the library with your Simulink model, and configuring the model to correctly utilize the library functions. Here is a step-by-step guide to help you through the process:
Step 1: Ensure Library Compatibility and Architecture
  • Library Architecture: Ensure that the library (.a or .so) is compiled for the same architecture as the Speedgoat target machine. Speedgoat systems typically use Intel x86_64 or ARM architectures. You might need to recompile the library if it was built for a different architecture.
  • Real-Time OS Compatibility: Speedgoat systems usually run a real-time operating system (RTOS) based on Linux. Ensure your library is compatible with this environment, especially if it's a dynamic library (.so), as it may have dependencies on other shared libraries.
Step 2: Include the Library in your Simulink Model
For Static Libraries (.a)
  • Place the .a file in a location accessible to MATLAB.
  • In your Simulink model, go to Model Settings (Ctrl+E) > Code Generation > Custom Code.
  • In the Include directories field, add the directory containing your .a file.
  • In the Source files field, add the path to your .a file.
  • In the Libraries field, add any additional libraries required by your static library.
For Dynamic Libraries (.so)
  • Ensure the .so file and any dependencies are on the Speedgoat target in a known directory.
  • You may need to set the "LD_LIBRARY_PATH" environment variable on the Speedgoat to include the directory containing your .so file. Please refer to the MATLAB Answer given below for further understanding
  • Reference the dynamic library in your Simulink model or S-function as needed. This typically involves loading the library and calling its functions via S-functions or MATLAB Function blocks.
Step 3: Configure Model for Speedgoat Deployment
  • In Simulink, go to Model Settings and select the Hardware Implementation pane.
  • Set the Hardware board to your specific Speedgoat target model.
  • Configure any additional settings specific to your application, such as I/O driver blocks for Speedgoat I/O modules.
Step 4: Build and Deploy
  • After configuring your model, click on Build Model to compile and deploy the model to your Speedgoat target.
  • Monitor the build process for any errors or warnings related to the library linking.
By following these steps, you should be able to successfully import and use your static or dynamic library within a Simulink model on a Speedgoat target. I hope you have followed a similar process in your case. If yes and still the error is there, here are several steps and considerations to help troubleshoot and potentially resolve the "Invalid or corrupted file" or "Cannot open file" errors.
Ensure Correct Library Path
  • Correct Path: Verify the library path specified in Model Settings > Code Generation > Custom Code section is correct and accessible. For static libraries, this includes the Include directories and Source files fields. For dynamic libraries, ensure the library's path is correctly specified or that the library is placed in a standard location on the Speedgoat.
Compiler and Linker Settings
  • Custom Compiler Options: Sometimes, specific compiler or linker flags are necessary to correctly link against certain libraries. This can include specifying the library path (-L) and the library to link against (-l).
  • Mismatched Toolchain: Ensure the toolchain used for compiling the library matches or is compatible with the toolchain used by MATLAB/Simulink for generating and compiling the model code. Mismatches here can lead to incompatibilities.
Additional Debugging Steps
  • Verbose Build: Enable verbose build output in Model Settings > Code Generation > Advanced Parameters to get more detailed information about the build process, which can help in identifying where the process fails.
  • Check Dependencies: For dynamic libraries, ensure all dependencies are present on the Speedgoat target. You can use tools like "ldd" on Linux to check for missing dependencies.
I hope this helps.
  2 Commenti
Pietro Di Maro
Pietro Di Maro il 22 Mar 2024
thanks for your exaustive answer :)
I'm quite sure that my problem relates this:
  • Real-Time OS Compatibility: Speedgoat systems usually run a real-time operating system (RTOS) based on Linux. Ensure your library is compatible with this environment, especially if it's a dynamic library (.so), as it may have dependencies on other shared libraries.
I know for sure that Speedgoat is running a QNX RTOS, but how can I build my library for it ? Do you have any experience in this ?
Kind regards
akshatsood
akshatsood il 23 Mar 2024
Hi @Pietro Di Maro, while I have limited experience in this area, I had like to suggest creating a Makefile that utilizes the "qcc" command for both compiling and linking your libraries. Additionally, for a dynamic library, it is benficial to include the "-shared" flag. You can then compile your library by executing "make". If your project targets a specific architecture, ensure to specify it by using the "-V" option alongside "qcc".

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by