How to compile so exe calls a .NET dll correctly?
Show older comments
I have a mfile mfileContainingDllCall.m that calls several .NET dlls succesfully in Matlab with these lines,
assemblyFile = 'firstNetDll.dll'; % This dll calls secondNetDll.dll
assert(exist(assemblyFile, 'file') == 2, 'File not found.' );
asm = NET.addAssembly(assemblyFile);
import firstNetDll.*
To make an executable version of the mfile, I compiled it as,
% Use -a to add the dlls, https://www.mathworks.com/help/compiler/mcc.html#mw_1a52a1c0-e230-4e98-be45-fad5d458fdec
mcc -m mfileContainingDllCall.m -a firstNetDll.dll -a secondNetDll.dll
When I run .\mfileContainingDll.exe from the Windows 11 command line, I get
'firstNetDll.dll' could not be found in the .NET Global Assembly Cache (GAC).
And if I put the following command in a try/catch structure,
try
NET.addAssembly(assemblyFile);
catch
disp('Failed NET.addAssembly(assemblyFile);')
end
it throws the catch error, so that's the command that is causing the issue.
The directory containing mfileContainingDllCall.m contains firstNetDll.dll and secondNetDll.dll because I think they have to be in the same directory and added with the -a flags.
I saw that Gacutil.exe can be used to resolve errors with the Global Assembly Cache, but the mfile doesn't give the GAC error, so I assume the error is in how I am calling mcc. I have Matlab compiler and R2023b.
What changes to the mcc command will prevent the GAC error?
Accepted Answer
More Answers (0)
Categories
Find more on Deploy to C++ Applications Using mwArray API (C++03) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!