Stateflow:​Unexpected​Error when generating Simulink model code in 2011a

9 views (last 30 days)
Hoping someone has seen this before. I try to generate code for my model and receive the following errors:
Making simulation target "MESR_MC_AC_ModeMgmt_sfun", ...
'MESR_MC_AC_ModeMgmt_sfun.bat' is not recognized as an internal or external command,
operable program or batch file.
A build_exception.mat file is created in the code output directory, and it contains an exception structure with the following identifier:
Stateflow:UnexpectedError
And a message that says:
'Error using ==> targetman>throw_make_error at 588
(SLSF Diagnostic)'
I'm on 2011a 64-bit, and using Microsoft Visual C++ 2010 Express compiler selected through mbuild -setup.
Any help would be much appreciated! Thanks! Justin

Answers (6)

Justin
Justin on 19 Aug 2011
For some follow-up, it seems to be related somehow to embedded matlab code blocks.. if I remove all of those, the model will build.
I've even removed all the blocks and replaced with a single embedded code block that looks like this:
function y = fcn(u)
%#codegen
y = u;
Not sure why it would be having problems with that, since it's the default code block from the Simulink libraries. Any chance it's a compiler config problem?

Kaustubha Govind
Kaustubha Govind on 19 Aug 2011
All Stateflow charts and Embedded MATLAB blocks generate C code and compile them for execution, the compiler selected using the MEX -SETUP command is invoked for the compilation and linking process. At this time, MATLAB spawns a system shell to run the compiler/linker commands. By default, the spawned shell starts in MATLAB's current directory - which means that the relevant batch/source/object file is expected to be in the present working directory.
However, if your system is configured to start the system shell in a different directory than the current one, this assumption fails.
To verify this execute the following commands in MATLAB (they should return the same path for the default configuration)
>> cd
>> !cd
If you find that the second command returns a different folder, check to see if you have made any settings to force a starting directory for cmd.exe. (One way that such a setting can be made is using the Windows Registry keys HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun (or) HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun)
Another thing to make sure is that you're not working in a UNC path (ie, a network directory that has not been mapped to a letter)

Justin
Justin on 19 Aug 2011
Hi Kaustubha,
Thanks for the reply and tips.
Unfortunately that didn't seem to be the problem. cd and !cd both return the same directory (the working directory for my model), and I have no suspect AutoRun reg entries in those locations.
I'm trying a change of path environment variables which had leftover path entries for 2010b and 2007b. I doubt those are the problem, as 2011a was first in the list.
I'll also try re-installing the MVC++ 2010 Express installation and make sure I selected the correct options re 64-bit.
I'm just not sure why it would let me successfully build a model without embedded code blocks, but die when I add even a very simple code block.
  7 Comments
Justin
Justin on 22 Aug 2011
No worries, thanks for your help. At least a few options have been eliminated. Have sent details and files to tech support. Will post here with the final solution once it's sorted (assuming there's an answer).
Cheers
Kaustubha Govind
Kaustubha Govind on 24 Aug 2011
Justin: One other thing - have you run "mex -setup" on your R2011a installation? It appears that this issue happens sometimes when you have a stale mexopts.bat files that R2011a is picking up.

Sign in to comment.


Stephen
Stephen on 30 Sep 2011
I had the same problem Justin did, but Kaustubha Govind's suggestion to run "mex -setup" solved the problem for me when I upgraded from Matlab R2010a to R2011a.

Justin
Justin on 30 Sep 2011
Oops, forgot to post here with the solution.
So turns out there are two problems at play.
First I had some kind of environment problem with my x64 compiler components of VC++ 2010 Express. For some reason the 64-bit components were not successfully installed when I installed the Windows SDK. Even uninstalling and re-installing did not solve the problem. Root cause of that is probably operator error, but can't be sure. I solved this by uninstalling everything related to Express, and installing full VS2010.
The symptom that tipped me off, for future reference, was that vcvars64.bat file (supposed to be created during the install) did not exist, as discovered by trying to execute "vsvarsall.bat x64" and other similar commands from the VS2010 Express install folder.
Second problem (I think the root of the Stateflow:UnexpectedError) appears to be a bug in loading models from a previous version. It arises from Embedded MATLAB code blocks with the following workaround:
- Load the model or copy blocks created in older Simulink version
- Unable to build due to the above error
- Open the embedded block and copy all text
- Create a new embedded block in the newer Simulink version
- Select all, and paste the copied text to replace the default code
- Delete original embedded block and replace with newly created one.
Seems there's something under the hood (i.e. not part of the embedded code text itself) causing the build problems once I got the environment set up right. Just re-creating the blocks using the current version of Simulink seems to set it straight.
All seems ok now. In the end we ended up going with 2010b for this project for unrelated reasons.
Cheers, Justin

Roque
Roque on 8 Feb 2014
I had the same problem, getting an error message that says:
'Error using ==> targetman>throw_make_error at 588 (SLSF Diagnostic)'
In my Simulink system I was using the Simulink Block "Matlab Function". I replaced that block with the "Interpreted Matlab Function" block and it worked perfectly.
I hope that this help.
Regards, Roque

Categories

Find more on Simulink Functions in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!