MCR issue at initialization
조회 수: 52 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (2개)
Tao Cui
2017년 12월 15일
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.
댓글 수: 0
Jerome Mai
2022년 4월 6일
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*.*\
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 C Shared Library Integration에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!