在MATLAB中使用mcc编译器时遇到问题(使用==>;mcc时出错,输出目录不存在)

在MATLAB中使用mcc编译器时遇到问题(使用==>;mcc时出错,输出目录不存在),matlab,.net-assembly,matlab-deployment,mcc,Matlab,.net Assembly,Matlab Deployment,Mcc,我试图通过在matlab2010b中执行此代码来构建.NET程序集文件 workdir = 'C:\Users\H\Documents\Source Code\MatlabFiles'; outdir = fullfile(workdir, 'Output'); dnetdir = fullfile(workdir, 'dotnet'); %% Determine file names mfile = fullfile(workdir, 'perform.m'); dnetdll = full

我试图通过在matlab2010b中执行此代码来构建.NET程序集文件

workdir = 'C:\Users\H\Documents\Source Code\MatlabFiles';
outdir = fullfile(workdir, 'Output');
dnetdir = fullfile(workdir, 'dotnet');

%% Determine file names
mfile = fullfile(workdir, 'perform.m');
dnetdll = fullfile(dnetdir, 'dotnet.dll');

%% Create directories if needed
if (exist(outdir, 'dir') ~= 7)
    mkdir(outdir);
end
if (exist(dnetdir, 'dir') ~= 7)
    mkdir(dnetdir);
end

%% Build .NET Assembly
eval(['mcc -N -d ' dnetdir ' -W ''dotnet:dotnet,' ...
        'dotnetclass,0.0,private'' -T link:lib ' mfile]);
我得到了这个错误

??? Error using ==> mcc
The output directory,
  'C:\Users\H\Documents\Project\thesis\Source'
does not exist.
我很确定这是因为目录路径“…\Source Code\…”中有空格。 因为如果我只使用另一条没有空格的路径,它的效果非常好

有没有办法让这一切顺利进行


谢谢。

我认为你的陈述存在实际问题。您可以通过连接字符串(如
dnetdir
mfile
)来构建一个要计算的字符串,每个字符串都有一个带有空格的文件路径。传递给EVAL的结果字符串如下所示:

mcc -N -d C:\Users\H\Documents\Source Code\MatlabFiles\dotnet -W ...
                                     ^--Look at that ugly space!
eval(['mcc -N -d ''' dnetdir ''' -W ''dotnet:dotnet,' ...
      'dotnetclass,0.0,private'' -T link:lib ''' mfile '''']);
mcc -N -d 'C:\Users\H\Documents\Source Code\MatlabFiles\dotnet' -W ...
您需要做的是构建字符串,以便在这些路径周围有撇号,如下所示:

mcc -N -d C:\Users\H\Documents\Source Code\MatlabFiles\dotnet -W ...
                                     ^--Look at that ugly space!
eval(['mcc -N -d ''' dnetdir ''' -W ''dotnet:dotnet,' ...
      'dotnetclass,0.0,private'' -T link:lib ''' mfile '''']);
mcc -N -d 'C:\Users\H\Documents\Source Code\MatlabFiles\dotnet' -W ...
这将导致一个如下所示的字符串:

mcc -N -d C:\Users\H\Documents\Source Code\MatlabFiles\dotnet -W ...
                                     ^--Look at that ugly space!
eval(['mcc -N -d ''' dnetdir ''' -W ''dotnet:dotnet,' ...
      'dotnetclass,0.0,private'' -T link:lib ''' mfile '''']);
mcc -N -d 'C:\Users\H\Documents\Source Code\MatlabFiles\dotnet' -W ...

现在,即使有这么大的空间,也会对其进行正确评估。

尝试将最后一行更改为:

eval(['mcc -N -d ''' dnetdir ''' -W ''dotnet:dotnet,' ...
    'dotnetclass,0.0,private'' -T link:lib ' mfile]);

请注意
dnetdir

周围的额外引号,我对
mcc
没有任何经验,但其他一些功能可能会遇到类似问题,因为大多数人习惯于使用命令模式(即类似于DOS、Linux、Mac等中的命令提示符)。但是,大多数函数实际上都是函数,因此您可以在函数模式中使用它们,并在括号中传递它们的参数

也可以在功能模式下使用,如帮助中所述。这可能看起来有点像:

mcc('-N', '-d', dnetdir, '-W', 'dotnet:dotnet,dotnetclass,0.0,private', '-T', 'link:lib', mfile);
这样,您就不必担心转义任何角色