Clear Filters
Clear Filters

How to create a linux shared object from matlab code (Matlab 2015b)

14 views (last 30 days)
Hello everyone,
I want to connect matlab written functions into our vehicle control unit. The control unit is a myRio 1900 which gets programmed with Labview. Until now I managed to create .dll files from my function by using the matlab coder. I could use the .dll running the labview code on windows.
But for now I am missing the last step as the myRio is running under Ni Realtime linux I cant use the .dll file anymore. I would need a linux shared object. Therefore I want to ask if and how I can create the .so file from matlab. It would be really benificial for the application if there werent to many steps involved as the process will get repeated quite frequently.
I found this question which exlained it for some older version but couldnt replicate the result. Apperently the usage of mcc has changed.
Currently I am using: Win 7 64bit Profesional, Matlab 2015b 32bit formula Student Licence (is there a way to create 32bit dlls from a 64bit Matlab?)
I appreciate any help!
Best Regards, Stephan

Accepted Answer

Christoph Hahn
Christoph Hahn on 11 Jul 2016
Dear Stephan,
regarding your first question, I have a twofold answer:
  1. Use a cross-compiling workflow such that one Cross-compiling on Windows for Linux
  2. MATLAB is also available on Linux OS: MathWorks Platform Availability . If that is a suitable workflow, you can do everything in Linux.
Concerning your question about 32/64bit compatiblity again there are two options:
  1. Stick to your workflow of using MATLAB 32bit
  2. Alternatively, ou need to create custom toolchain which allows you to call the 32-bit version of the Microsoft Visual Studio Compiler.
The workflow for the 2nd option is as follows:
Please execute the "generate_32_bit_dll" function to create the custom toolchain which generates 32 bit DLL using ert_shrlib.TLC and choose 'Microsoft 64-bit compiler targeting 32-bit DLL | nmake makefile (64-bit Windows)' for the toolchain in the model's Configuration Parameters > Code Generation pane. How can I build a 32-bit shared library (DLL) with Embedded Coder on Windows 64-bit MATLAB? Answer You need to create custom toolchain which allows you to call the 32-bit version of the Microsoft Visual Studio Compiler.
Please execute the "generate_32_bit_dll" function to create the custom toolchain which generates 32 bit DLL using ert_shrlib.TLC and choose 'Microsoft 64-bit compiler targeting 32-bit DLL | nmake makefile (64-bit Windows)' for the toolchain in the model's Configuration Parameters > Code Generation pane.
Let me know whether these answers are helpful to you!
Cheers, Christoph
  2 Comments
Walter Roberson
Walter Roberson on 11 Jul 2016
Note: the 32 bit executables that Christoph describes are Windows 32 bit executables. If the requirement is to generate 32 bit Linux executables then you need to go through a cross-compiling setup. Also, MATLAB is no longer available to run on 32 bit Linux natively.
Stephan Heidrich
Stephan Heidrich on 18 Jul 2016
Hello Christoph and Walter,
thank you both for your help and directing.
First I was trying to use matlab 2012a 32bit coder installed on a linux which got me a .so file. Unfortunately it didnt work with our rt system (eventhough I was setting it to ARM Cortex A).
The second approach with the cross compiling was bringing the right results. In cooperation with Ni I was using the two following tutorials to create the .so from the matlab exported c files:
Tutorial how to (unfortunately in German)

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 10 Jul 2016
It is not that mcc has changed (though it has) but rather that you are trying to "cross-compile", creating a Linux library from MS Windows. MATLAB Coder should be able to do that if you configure the correct toolchain; unfortunately I do not know what the correct toolchain is (especially not for a realtime Linux.)
For example, MATLAB Coder is invoked by Simulink to build models for deployment on Arduino, which uses Linux, so it must be possible to configure. I have not had reason to do that myself (I do not have any Linux hardware.)

Community Treasure Hunt

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

Start Hunting!