Problem with all Simulink embedded coder examples

14 ビュー (過去 30 日間)
Robert Scott
Robert Scott 2023 年 1 月 10 日
移動済み: Fangjun Jiang 2023 年 1 月 18 日
so i can not get any of the simulink embedded coder examples to actually generate code.
I have tried several of them as well as making my own very simple model of just a 2 number adder.
Whenever i try to generate code either with CTRL B and or using the generate code wizard i get the exact same error.
The error you would think is benign until you dig further.
### Starting build procedure for: rtwdemo_roll
### Build procedure for rtwdemo_roll aborted due to an error.
Build Summary
Top model targets built:
Model Action Rebuild Reason
========================================================================
rtwdemo_roll Failed Code generation information file does not exist.
0 of 1 models built (0 models already up to date)
Build duration: 0h 0m 24.262s
Index exceeds the number of array elements. Index must not exceed 0
So this error would tell me normally i goofed somewhere except its the same error on every matworks example. I am not building the model just following the instructions.
So i ran the build from matlab to see if i could get anymore diagnostic info and i get this
rtwdemo_roll Failed Code generation information file does not exist.
0 of 1 models built (0 models already up to date)
Build duration: 0h 0m 19.946s
Index exceeds the number of array elements. Index must not exceed 0.
Error in coder.make.internal.applyMsvcEnvironment>i_runMsvcSetupCommand (line 82)
deltaNames{i} = toks{i}{1};
Error in coder.make.internal.applyMsvcEnvironment (line 24)
i_runMsvcSetupCommand(mexCompDetails);
Error in codebuild>i_setupEnvironment (line 479)
environmentCleanupFcn = coder.make.internal.applyMsvcEnvironment(mexCompDetails);
Error in codebuild (line 142)
environmentCleanupFcn = i_setupEnvironment...
Error in coder.internal.ModelBuilder>i_buildProcedure (line 1523)
compileResult = codebuild(lBuildInfoUpdated, compileBuildOptsUpdated);
Error in coder.internal.ModelBuilder.make_rtw (line 119)
[buildResult, mainObjFolder] = i_buildProcedure...
Error in build_target
Error in build_target
Error in build_standalone_rtw_target
Error in slbuild_private
Error in slbuild_private
Error in sl_feval
Error in slbuild
Error in slbuild
Error in rtwbuild
The error appears to be deeply rooted on line 82 of some buried matlab file. I went to and set a break point there only to find some issue with some enviroment variable and the size of some variable named toks
I am at a complete loss. I have several versions of matlab and have tried them all. I get the same error.
Here is the file that line 82 is causing problems in
function [cleanupFcn, useCachedSettings] = applyMsvcEnvironment(mexCompDetails)
% applyMsvcEnvironment
% Copyright 2021 The MathWorks, Inc.
mlock
persistent cachedEnvironmentKey
persistent deltaNames
persistent deltaValues
persistent pathPrepend
persistent pathAppend
% Check if requested environment settings are consistent with cached
% settings
environmentKey = ...
[mexCompDetails.CommandLineShell ' ' mexCompDetails.CommandLineShellArg];
useCachedSettings = ~isempty(cachedEnvironmentKey) && ...
strcmp(environmentKey, cachedEnvironmentKey);
if ~useCachedSettings
% Need to determine environment settings by running VCVARSALL.BAT
[deltaNames, deltaValues, pathPrepend, pathAppend] = ...
i_runMsvcSetupCommand(mexCompDetails);
end
% Capture original value of each environment variable that will be set
variablesToRestore = deltaNames;
originalValues = cell(size(variablesToRestore));
for i=1:length(originalValues)
originalValues{i} = getenv(variablesToRestore{i});
end
variablesToRestore{end+1} = 'PATH';
originalPath = getenv('PATH');
originalValues{end+1} = originalPath;
% Cleanup function to restore original environment variables
cleanupFcn = onCleanup(@()i_setEnvVars(variablesToRestore, originalValues));
% Apply the new environment settings
i_setEnvVars(deltaNames, deltaValues);
setenv('PATH', [pathPrepend originalPath pathAppend]);
% Finally, allow the environment variables to be reused next without
% re-running VCVARSALL.BAT
cachedEnvironmentKey = environmentKey;
function i_setEnvVars(vars, values)
for i=1:length(vars)
setenv(vars{i}, values{i});
end
function [deltaNames, deltaValues, pathPrepend, pathAppend] = ...
i_runMsvcSetupCommand(mexCompDetails)
% Generate batch file content to print out the environment after
% VCVARSALL.BAT has run
markerOutput = '===PRINT ENVIRONMENT===';
trailer = ['echo ' markerOutput];
trailer = [newline trailer newline newline 'SET'];
batchFileName = [tempname '.bat'];
coder.make.internal.writeMsvcSetup(batchFileName, mexCompDetails, ...
'Trailer', trailer);
% Capture original environment
[~, originalVars] = system('SET');
originalVars = splitlines(string(originalVars));
% Capture environment after running the setup command
[~, updatedVars] = system(batchFileName);
updatedVars = regexprep(updatedVars, ['.*\s+' markerOutput '\s+'], '');
updatedVars = splitlines(string(updatedVars));
% Identify variables that changed
deltaVars = setdiff(updatedVars, originalVars);
toks = regexp(deltaVars, '(\w+)=(.*)', 'tokens', 'once');
deltaNames = cell(size(toks));
deltaValues = cell(size(toks));
for i=1:length(toks)
deltaNames{i} = toks{i}{1};
deltaValues{i} = toks{i}{2};
end
% If the path was updated identify the part that was prepended
pathIdx = strcmpi(deltaNames, 'PATH');
if sum(pathIdx)>0
assert(sum(pathIdx)==1, 'Must be only one match for PATH')
updatedPath = deltaValues{pathIdx};
originalPath = getenv('PATH');
% VCVARSALL.BAT might strip off a trailing semicolon: apply the same
% cleanup to the path that we check for in the updated path
originalPathCleaned = regexprep(originalPath, ';+$', '');
% Running VCVARSALL typically prepends and in some cases additionally
% appends to the path
k = strfind(updatedPath, originalPathCleaned);
if isempty(k)
assert(false, ...
['After running VCVARSALL.BAT, the updated path, "%s", ' ...
'must contain the original path, "%s"'], ...
updatedPath, originalPathCleaned);
end
pathPrepend = updatedPath(1:k(end)-1);
pathAppend = updatedPath(k(end)+length(originalPathCleaned):end);
deltaNames = deltaNames(~pathIdx);
deltaValues = deltaValues(~pathIdx);
else
pathPrepend = '';
pathAppend = '';
end
Anyone have any ideas?

採用された回答

Robert Scott
Robert Scott 2023 年 1 月 18 日
移動済み: Fangjun Jiang 2023 年 1 月 18 日
If anyone else runs into this, the solution was a stray double quote in my path variable causing all the models to fail.
The solution was found in this stack overflow post.

その他の回答 (0 件)

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by