Dear sir or madam,
i have used the matlab compiler (R2012a) to make a shared library (.dll) of some of my matlab code.
then I link this library in a c++ win32 console program(development IDE is VS2010).
the code run well,but whenever I click 'Close' button on the top right corner of the win32 console forms to quit, unexpected breakpoint was triggered and the program can't quit normally.
here's some details illustrations:
------------------------------------------------
1) main funtion segment:
int _tmain(int argc, _TCHAR* argv[])
{
//Initialize------
//// call fuction from self compile lib
if(!libsen_tradeInitialize())
{
std::cout <<"------------------????Could not initialize StrategyLib????-----------------------!" << std::endl;
getchar();
return -1;
}
...
//......Release Resource
// terminate MCR
libsen_tradeTerminate();
mclTerminateApplication();
return 0;
}
--------------------------------------------------------------
2) call stack shows:
> libifcoremd.dll!0cbfc25b()
[Frames below may be incorrect and/or missing, no symbols loaded for libifcoremd.dll]
libmmd.dll!0ceaf0bf()
libmmd.dll!0ceaefbb()
apphelp.dll!70b6fff6()
libmmd.dll!0ceaf11d()
libmmd.dll!0ceace0d()
libmmd.dll!0ceace15()
ntdll.dll!776999a0()
ntdll.dll!7769a15e()
ntdll.dll!77699f45()
------------------------------------------------
3) the following statement is printed, program can't terminate normally:
forrtl: error (200): program aborting due to window-CLOSE' event
4) finally I found that if I comment out the code block
/*
if(!libsen_tradeInitialize())
{
std::cout <<"------------------????Could not initialize StrategyLib????-----------------------!" << std::endl;
getchar();
return -1;
}
*/
the program can quit normally, but this is necessary for invoking matlab funtion.
many search has been done on the internet and few-to-no result for 'forrtl: error (200):' except
http://www.mathworks.com/matlabcentral/newsreader/view_thread/251203
and
http://stackoverflow.com/questions/15457786/ctrl-c-crashes-python-after-importing-scipy-stats
problem post on http://www.mathworks.com/matlabcentral/newsreader/view_thread/251203 is very similar to me,
but while I am a newer of c++ and matlab, I can't exactly understand the solution of
------------------------------------------------------------------------------------
i'm just using signal to catch SIGINT. the handler is set up after all the MCR init stuff.
it turned out that the answer was that we weren't waiting long enough for the MCR initialization to complete. it was unexpected that the initialization took on the order of a minute or more. when we terminated things early, we got a surprising fortran signal handling!
------------------------------------------------------------------------------------
has anyone run into this problem before ? can you please give me detail explanation ?
thanks you very much!
Zhishang