Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Posted
Comments
Richard MacCutchan 1-May-14 7:10am    
Why are you using std::cout in a Windows program?
Member 10362802 1-May-14 7:16am    
sorry for the poor hand writing.<br>
 <br>

Actually, I am invoking matlab function in a c++ win32 console project.
Richard MacCutchan 1-May-14 7:25am    
Then you should not be closing the console window before the program terminates.
Member 10362802 1-May-14 9:52am    
Thanks for you kindly help!

Actually, I am building a trade system, the cpp program is a multi-thread project,
receiving market data then sending this data to the strategy by invoking matlab function,
finally send order according to the return value.

the program will not end except shutdown manually.

do you mean I should catch the 'windows-close' event then release the resource before invoking

//libsen_tradeTerminate();
//mclTerminateApplication();


Thanks!
Richard MacCutchan 1-May-14 9:56am    
You cannot catch events in a console application.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900