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
0 个评论
回答(2 个)
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 个评论
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
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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!