MATLAB: Am I receiving a “cannot open output file” error while trying to run a Simulink model with an Embedded MATLAB block

simulink coder

I have a model with an Embedded Matlab (EML) block. When I run the model, code is generated for the EML block and I receive the following error:
Making simulation target "call_stats_block2_sfun", ...
U:\My Documents\matlab_work\state_test\sfprj\build\call_stats_block2\sfun\src>"c:\matlab7\sys\lcc\bin\lccmake" -f call_stats_block2_sfun.lmk
cannot open output file call_stats_block2_sfun.dll:
"c:\matlab7\sys\lcc\bin\lcc.exe" -c -Zp8 -DMATLAB_MEX_FILE -noregistrylookup -I"c:\matlab7\sys\lcc\include" -I"c:\matlab7\extern\include" -I"c:\matlab7\simulink\include" -I"c:\matlab7\stateflow\c\mex\include" -I"c:\matlab7\stateflow\c\debugger\include" -I"u:\my documents\matlab_work\state_test\sfprj\build\call_stats_block2\sfun\src" -I"u:\my documents\matlab_work\state_test"" ""call_stats_block2_sfun.c"
"c:\matlab7\sys\lcc\bin\lcc.exe" -c -Zp8 -DMATLAB_MEX_FILE -noregistrylookup -I"c:\matlab7\sys\lcc\include" -I"c:\matlab7\extern\include" -I"c:\matlab7\simulink\include" I"u:\my documents\matlab_work\state_test\sfprj\build\call_stats_block2\sfun\src" -I"u:\my documents\matlab_work\state_test"" ""call_stats_block2_sfun_registry.c"
"c:\matlab7\sys\lcc\bin\lcc.exe" -c -Zp8 -DMATLAB_MEX_FILE -noregistrylookup -I"c:\matlab7\sys\lcc\include" -I"c:\matlab7\extern\include" -I"c:\matlab7\simulink\include" -I"c:\matlab7\stateflow\c\mex\include" -I"c:\matlab7\stateflow\c\debugger\include" -I"u:\my documents\matlab_work\state_test\sfprj\build\call_stats_block2\sfun\src" -I"u:\my documents\matlab_work\state_test"" ""c2_call_stats_block2.c"
"c:\matlab7\sys\lcc\bin\lcc.exe" -c -Zp8 -DMATLAB_MEX_FILE -noregistrylookup -I"c:\matlab7\sys\lcc\include" -I"c:\matlab7\extern\include" -I"c:\matlab7\simulink\include" -I"c:\matlab7\stateflow\c\mex\include" -I"c:\matlab7\stateflow\c\debugger\include" -
c:\matlab7\sys\lcc\bin\lccmake: Error code -1

Best Answer

You receive this error because Simulink is unable to delete and/or create a new DLL file for the Embedded MATLAB block. The two most likely causes are:
1) The current directory might not have the appropriate permissions or
2) the previously created DLL is in use by some other model or application and hence MATLAB is unable to delete and re-create it.
To work around the first issue you can set the file permissions for the working directory to allow both read and write access. For the second issue execute the following command at the MATLAB command prompt:
clear mex
Then delete the previously created DLL file and try running the model.