MCR issue at initialization

38 views (last 30 days)
Bruno
Bruno on 15 Jan 2013
Answered: Jerome Mai on 6 Apr 2022
I'm facing a weird issue. My Application can use MATLAB code embedded in plugin DLL. I've generated C++ shared dll using MATLAB Compiler 4.18. Two months ago everything went fine, the Matlab generated dll was used by another dll which is a wrapper for my application written in C++.
Now I want to build another MATLAB dll and wrap it the same way, but the libInitialize() call fails.
Here is part of the code doing initializations :
// in the wrapper DLL a constructor is initializing the MATLAB part
MyDll::MyDll()
{
mclmcrInitialize();
if (mclInitializeApplication(NULL, 0))
if (myLibInitialize())
...
}
When debugging i've found that the crash is here:
bool myLibInitializeWithHandlers(
mclOutputHandlerFcn error_handler,
mclOutputHandlerFcn print_handler)
{
int bResult = 0;
if (_mcr_inst != NULL)
return true;
if (!mclmcrInitialize())
return false;
if (!GetModuleFileName(GetModuleHandle("myLib"), path_to_dll, _MAX_PATH))
return false;
{
mclCtfStream ctfStream =
mclGetEmbeddedCtfStream(path_to_dll);
if (ctfStream) {
bResult = mclInitializeComponentInstanceEmbedded( &_mcr_inst,
error_handler,
print_handler,
ctfStream);
mclDestroyStream(ctfStream);
} else {
bResult = 0;
}
}
if (!bResult)
return false;
return true;
}
Crash in mclInitializeComponentInstanceEmbedded which i can't debug trace since it's part of MCR. I've noticed, though, that _mcr_inst pointer is always NULL. Is it the source of the issue?
I've lost my mind since the same code worked perfectly two months ago on my PC. I changed nothing, MATLAB is still 2012b, Matlab Compiler 4.18 and MCR installed on my Windows 7 64bit.
I guess the issue is linked to CTF acces problem. I tried to build my Matlab C++ DLL with no ctf embedded, same result.
I tried with simple matlab code in one .m file, same result.
Any suggestions appreciated.
Bruno

Answers (2)

Tao Cui
Tao Cui on 15 Dec 2017
not sure if your problem was solved since this is an old post. I have encountered same issue and this post solved my problem: https://stackoverflow.com/questions/18512801/call-matlab-dll-from-c-fail-to-initialize-the-library
Simple solution: do not include Matlab generated CPP files into your project, just use the header and the lib.

Jerome Mai
Jerome Mai on 6 Apr 2022
You need to delete the mcrCache folder to get it working again.
Run this in Matlab to find out the folder path:
mcrcachedir
It may be something like:
C:\Users\<user>\AppData\Local\Temp\<user>\mcrCache*.*\

Categories

Find more on C Shared Library Integration in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!