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

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

Réponses (6)

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?
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 le 19 Août 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 commentaires

Are you running on Windows 7 by any chance? If so, could you try starting MATLAB as Administrator and try again? My best bet is that Windows is not allowing MATLAB to generate any files to the folder.
Thanks again for your reply.
Yep I'm using Win7 64-bit. Just tried running as Administrator but had the same error. It seems to write out a lot of other files. I get ..._grt_rtw and slprj folders created by Matlab, so it seems to have permission to create files.
'MESR_MC_AC_ModeMgmt_test_sfun.bat' is not recognized as an internal or external command, operable program or batch file.
This seems to be a symptom rather than the problem... I'm not sure what Stateflow:UnexpectedError is, but I can build just fine if I remove the embedded code block from the model.
Do you see MESR_MC_AC_ModeMgmt_test_sfun.bat inside the slprj folder? If yes, could you try running it from MATLAB like so:
>> !MESR_MC_AC_ModeMgmt_test_sfun
The Stateflow:UnexpectedError is coming from the Embedded MATLAB not being able to build generated code that it uses for execution. (Embedded MATLAB block uses some Stateflow-based infrastructure).
Hi again. Thanks for your help through this.
There is no bat file produced that I can see. I see the original "not recognized" error when I try to run it from either the main directory or the slprj directory.
I've found I CAN build successfully under MATLAB 2010b. I was able to save my model from 2011a to the older version, and it worked when built from 2010b, so I think I'll be forced to revert to that.
In 2010b I set mex -setup to look for the same VC++ Express 2010 compiler. So something is wrong in 2011a, either in the release or in my configuration of it.
Let me know if you have any ideas. I can continue with 2010b, but would prefer to use 2011a if it can be made to work.
Cheers, and thanks,
Justin
Sorry, I've run out of ideas with this. I would recommend contacting Tech Support to see if they can help. Good luck!
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
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.

Connectez-vous pour commenter.

Stephen
Stephen le 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 le 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 le 8 Fév 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

Catégories

En savoir plus sur Simulink Coder dans Centre d'aide et File Exchange

Question posée :

le 19 Août 2011

Réponse apportée :

le 8 Fév 2014

Community Treasure Hunt

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

Start Hunting!

Translated by