Matlab shared library is not initialized in release directory from Visual C++/CLI program
4 views (last 30 days)
Show older comments
Hello,
I have programmed a small application in Visual C++/CLI (Visual Studio 2012 Professional) in which I call a Matlab function. This Matlab function has been compiled to a C++ shared library by the Matlab Compiler R2012a. I'm working with Windows 7, 64 Bit, but my program and library are compiled for 32 Bit.
Up to now I always started the program in the debug mode directly from Visual C++ and everything worked fine, especially the calling of the Matlab function did not give any problems. But now I wanted to compile the program in release mode and tried to start it separately from Visual studio. In the beginning there were some problems with Matlab DLLs (could not be found), so I simply copied all DLLs to the release directory (there may be some better method). Now the program seems to start, but when it tries to load my Matlab library it stops without any message. Here is a small code snippet which shows how I load my Matlab library:
try {
MessageBox::Show("Before mclInitializeApplication");
// initialize MCR
if (!mclInitializeApplication(NULL,0)) {
MessageBox::Show("Can't initialize MCL");
this->~Form1();
} else {
MessageBox::Show("Before thermoMatlabLibInitialize");
if(!thermoMatlabLibInitialize()) {
MessageBox::Show("Could not initialize the thermoMatlab-library");
this->~Form1();
}
}
} catch (const mwException& e) {
MessageBox::Show("Caught mwException");
}
The first two success-MessageBoxes are displayed ("Before mclInitializeApplication" and "Before thermoMatlabLibInitialize") but then neither "Could not initialize the thermoMatlab-library" nor "Caught mwException" is shown. Furthermore, there is no system error from Windows about the application either. The file "thermoMatlabLib.dll" is also contained in the release directory.
Does anyone know why this happens? Why is the exception not caught? Is it the wrong exception type or is there no exception at all?
Thank you very much in advance! Oliver
4 Comments
Kaustubha Govind
on 19 Sep 2013
The DLL file is loaded at run-time, so its location needs to be added to the system PATH environment variable.
Accepted Answer
More Answers (0)
See Also
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!