identical code works fine in matlab 2015b but not in matlab 2016b

1 次查看(过去 30 天)
Hi, I'm using matlab coder that generates this code:
fileName = [fileName '.bin'];
fid = fopen(fileName, 'w');
if fid == -1
error(['Cannot open output file ' fileName ' for writing']);
end
% some code here
fwrite(fid, var1, 'int32');
fclose(fid);
While running the code created from the coder used in matlab 2015b it works without any errors. While running the code created from the coder used in matlab 2016b I get the following error:
Undefined function 'coder.internal.ifWhileCondExtrinsic' for input arguments of type 'logical'.
Error in fileManager>fileclose (line 143) if failp
Error in fileManager (line 23) f = fileclose(varargin{1});
Error in fclose (line 15) st = double(fileManager('close',fileID));
Error in coder_file_name (line 8) fclose(fid);
The fopen and fwrite works, as proof the file does created, But I do get the bizarre error. What is wrong?
Thanks

回答(2 个)

Steven Lord
Steven Lord 2016-11-2
Have you created your own fclose function that's shadowing the one included in MATLAB? You can check this using the which function.
which -all fclose
In release R2016b the fclose.m file has a line 15. However since fclose is a built-in function fclose.m contains only help text and line 15 is a blank line, the last line in the file. That's why I suspect you've created your own function by that name. Rename or remove that function.
  2 个评论
nad yah
nad yah 2016-11-2
编辑:nad yah 2016-11-2
I didn't add any implementation for fclose. Notice:
  1. When I used the command you said I get those three paths:
built-in (/opt/matlab/R2016b/toolbox/matlab/iofun/fclose)
/opt/matlab/R2016b/toolbox/shared/instrument/@icinterface/fclose.m % icinterface method
/opt/matlab/R2016b/toolbox/matlab/serial/@serial/fclose.m % serial method
But When I press the Error line of fclose.m I get this code:
Path for that code:
/opt/matlab/R2016b/toolbox/eml/lib/matlab/iofun/fclose.m
In addition, While running this code from the same machine who generates this code using the coder it works fine. But when I copy the mex file created from the coder to another machine I get this error, But it does knows to go to the correct path but. What is the problem? In 2015b I did the same process which worked well.
Steven Lord
Steven Lord 2016-11-2
Okay, so it is MATLAB Coder itself that has defined a code generation version of fclose. I'm not very familiar with MATLAB Coder, so I don't know why that's not working. You're probably going to want to contact Technical Support via the Contact Us link in the upper-right corner of this page.

请先登录,再进行评论。


Ryan Livingston
Ryan Livingston 2016-11-6
编辑:Ryan Livingston 2016-11-16
A MATLAB bug report has been published for this issue:
which contains a patch that can be applied into a MATLAB installation.
It looks like the function ifWhileCondExtrinsic may not be installed without MATLAB Coder being installed even though the MATLAB Coder MEX file is depending on that file. I reported this to the MATLAB Coder development team.
For a quick workaround, on your machine with MATLAB Coder you can run:
which coder.internal.ifWhileCondExtrinsic
and then copy that file to your machine which doesn't have MATLAB Coder to the directory:
$MATLABROOT/toolbox/shared/coder/coder/+coder/+internal/
where $MATLABROOT is the result of running the command matlabroot in your target MATLAB installation.
You may need to run rehash toolboxcache after copying the file to make sure MATLAB recognizes it. Run:
which coder.internal.ifWhileCondExtrinsic
after the copy to verify that MATLAB recognizes the file then your MEX should execute properly.

Community Treasure Hunt

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

Start Hunting!

Translated by