Calling Matlab Compiler from inside C# app throws exception

I found this code to invoke the Matlab compiler, it works fine when the function is called from Matlab command prompt, I build this function to .Net Assembly but whenever I try to use it in my C# app in order to build some .m file I get an exception, where do you think my problem is?
Matlab Code:
function compileCode(mfile,dllName , dnetdir)
%%Create directories if needed
if (exist(dnetdir, 'dir') ~= 7)
mkdir(dnetdir);
end
%%Build .NET Assembly
eval(['mcc -N -d ''' dnetdir ''' -W ''dotnet:' dllName ',' ...
'' dllName ',0.0,private'' -T link:lib ''' mfile '''']);
end
C# code:
var cmm = new compiler.MatlabCompiler();
MWCharArray x = new MWCharArray(@"C:\Users\ePezhman\Documents\MATLAB\Graph2D.m");
MWCharArray y = new MWCharArray("Graph");
MWCharArray z = new MWCharArray(@"C:\Matlab\dotnet");
cmm.compileCode(x,y,z);
Exception:
... MWMCR::EvaluateFunction error ... Undefined function 'mcc' for input arguments of type 'char'. Error in => compileCode.m at line 9.
... Matlab M-code Stack Trace ... at file C:\Users\ePezhman\AppData\Local\Temp\ePezhman\mcrCache8.0\compil0\compiler\compileCode.m, name compileCode, line 9.

回答 (1 件)

Walter Roberson
Walter Roberson 2013 年 3 月 29 日

0 投票

Try,
function compileCode(mfile,dllName , dnetdir)
%%Create directories if needed
if (exist(dnetdir, 'dir') ~= 7)
mkdir(dnetdir);
end
%%Build .NET Assembly
mcc('-N', '-d', dnetdir, '-W', ['dotnet:' dllName ',' ...
dllName ',0.0,private'], '-T', 'link:lib', mfile);
end

2 件のコメント

Pezh
Pezh 2013 年 3 月 29 日
get this exception now, any idea :
... MWMCR::EvaluateFunction error ...
Invalid MEX-file 'C:\Users\ePezhman\AppData\Local\Temp\ePezhman\mcrCache8.0\compil1\toolbox\compiler\mcc.mexw32': C:\Users\ePezhman\AppData\Local\Temp\ePezhman\mcrCache8.0\compil1\toolbox\compiler\mcc.mexw32 is not a valid Win32 application.
Error in => compileCode.m at line 7.
... Matlab M-code Stack Trace ...
at
file C:\Users\ePezhman\AppData\Local\Temp\ePezhman\mcrCache8.0\compil1\compiler\compileCode.m, name compileCode, line 7.
Walter Roberson
Walter Roberson 2013 年 3 月 29 日
When you get that, it usually means that there is a runtime library missing from your execution path. Try downloading Dependency Walker (from the internet) and using it to track which libraries are needed for mcc. It might turn out to be a matter of adjusting an environment variable.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeMATLAB Compiler についてさらに検索

質問済み:

2013 年 3 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by