How can I compile an executable in Simulink on Windows to run from Matlab on Linux or from a Linux command line?

24 ビュー (過去 30 日間)
Hi,
I have created a Simulink model with MATLAB version R2012a on Windows 7, and want to run it on my University's advanced computing cluster. However, the cluster runs on a Linux based OS (Red Hat) and does not have a Simulink license. So, I used the code generation package in Simulink to create and executable file that I can run using MATLAB. However, I cannot get the executable to run through the Linux MATLAB on the cluster. I receive the error "/bin/bash: ./HLE.exe: cannot execute binary file".
I will explain the small bit of troubleshooting I have done already, in case I have screwed something up.
When I run the executable on my Windows machine, the file executes correctly. However, when I transfer the files to the cluster and run from the Linux version of MATLAB (also 2012a), I receive some errors.
In Windows MATLAB my command is
>> !HLE.exe -i input.mat
If I try to use the same command as above in Linux MATLAB, I receive the error "/bash/bin: HLE.exe: command not found". This is apparently a problem with the path, and can be fixed using the command
>> !./HLE.exe -i input.mat
However, I received a permission error. To resolve this I changed the permissions of the file by using "chmod 755 HLE.exe" from the Linux command line.
Running the same command again from Linux MATLAB on the cluster, I receive a new and different error.
>> !./HLE.exe -i input.mat
/bash/bin: ./HLE.exe: cannot execute binary.
Here is where I am stuck. This says to me that the exe simply won't work using the MATLAB version on Linux. How can I work around this?
Can I somehow compile differently, perhaps choose a different code generation target, to make an executable that works with the Linux MATLAB? Or perhaps I can compile to run the executable stand alone on the Linux command line? Or can I somehow compile the C code and make file generated by Simulink with Linux to run stand alone?
Thanks!
-Kevin
A little more info! I am using the rsim.tlc system target file to generate C code from using the Simulink code generation packages.

回答 (1 件)

Kaustubha Govind
Kaustubha Govind 2013 年 4 月 12 日
  1. The rsim.tlc is meant for rapid prototyping on a machine where MATLAB/Simulink is installed, and therefore does not generate completely standalone code. If you'd like to run the code on a machine without access to Simulink, you probably want to use grt.tlc that comes with the Simulink Coder product.
  2. You are generating code on a Windows machine with produces a Windows-specific binary (the .exe extension denotes a Windows executable). If you have access to Simulink on a Linux machine, that would be the easiest way to obtain a Linux executable instead. If that is not possible, please read this blog post to see how you can relocate the generated code to another machine to compile. Note that you will need to figure out the right build commands to use, since on a Windows machine, Simulink Coder will generate a Makefile meant for Windows.
  1 件のコメント
Kevin Zaseck
Kevin Zaseck 2013 年 4 月 15 日
Thanks!
Your info helped me fix most of my issues, but I have some new ones. Namely, how does the executable built with the grt.tlc target accept an input from the linux or matlab command line?
As you suggested, by generating the code with grt.tlc and compiling on a Linux machine, I am able to create an executable that works on the cluster. However, I can't figure out how to supply an input file to the new executable.
When I compiled with rsim.tlc in the past, I could create an input file and call the function from the command line as follows.
>> t = [0;0.5]; u = [2000 0;2000 0];
>> tu = [t,u];
>> save('input.mat','tu')
linux command line: # ./HLE -i input.mat
where HLE is my executable. Now that I generate and compile code with the grt.tlc target, that input structure does not work. This may be an issue with my Linux familiarity, but how does the executable built with the grt.tlc target accept an input from the linux or matlab command line?
Thanks, -Kevin

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSimulink Coder についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by