开发者

I have trouble using mcc compiler in MATLAB (Error using ==> mcc The output directory does not exist)

开发者 https://www.devze.com 2023-03-01 23:34 出处:网络
I\'m trying to build the .NET assembly file by executing this code in matlab2010b workdir = \'C:\\Users\\H\\Documents\\Source Code\\MatlabFiles\';

I'm trying to build the .NET assembly file by executing this code in matlab2010b

workdir = 'C:\Users\H\Documents\Source Code\MatlabFiles';
outdir = fullfile(workdir, 'Output');
dnetdir = fullfile(workdi开发者_运维百科r, '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]);

I'm getting this error.

??? Error using ==> mcc
The output directory,
  'C:\Users\H\Documents\Project\thesis\Source'
does not exist.

I'm pretty sure it's because of the space in the directory path "...\Source Code\...". Because if I just use another path with no spaces it works perfectly fine.

Is there a way to make this work?

Thank you.


I think the actual problem occurs with your EVAL statement. You build a string to evaluate by concatenating strings like dnetdir and mfile, each of which will have a file path with a space in it. The resulting string you pass to EVAL will look like this:

mcc -N -d C:\Users\H\Documents\Source Code\MatlabFiles\dotnet -W ...
                                     ^--Look at that ugly space!

What you need to do is build your string so that there are apostrophes around these paths, like this:

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

Which will result in a string that looks like this:

mcc -N -d 'C:\Users\H\Documents\Source Code\MatlabFiles\dotnet' -W ...

And which will be evaluated properly now even with that nasty space in there.


I don't have any experience with mcc but some other functions may suffer from similar problems since most people are used to using the command mode (i.e. similar to the command prompt in DOS, Linux, Mac, ...). However, most functions are really functions such that you can use them in function mode and pass their arguments within parentheses.

You can also use mcc in function mode, as described in the help. That might look somewhat like:

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

That way you should not have to worry about escaping any character.


try changing the last line to:

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

note the extra quotes around dnetdir

0

精彩评论

暂无评论...
验证码 换一张
取 消