フィルターのクリア

MCR issue at initialization

52 ビュー (過去 30 日間)
Bruno
Bruno 2013 年 1 月 15 日
回答済み: Jerome Mai 2022 年 4 月 6 日
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

回答 (2 件)

Tao Cui
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.

Jerome Mai
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*.*\

カテゴリ

Help Center および File ExchangeC Shared Library Integration についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by