Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

Matlab shared library is not initialized in release directory from Visual C++/CLI program

Asked by Oliver on 18 Sep 2013

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

Oliver on 19 Sep 2013

No, unfortunately not. After mclInitializeApplication the return value of mclGetLastErrorMessage is an empty string and if I call it after thermoMatlabLibInitialize() it is not reached.

Is there anything I have to regard when using Matlab libs in release mode?

In Visual C++ I specified the location of the .h and .lib file. I also added the .lib-file in the "Additional dependencies" section of the linker settings. Do I have to do anything like this with the .dll-file?

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.

Oliver on 19 Sep 2013

I tried this, but it doesn't work either ... do you have any further ideas? Thanks for helping me!

Oliver

Products

1 Answer

Answer by Oliver on 20 Sep 2013
Accepted answer

Ok, I did the setup of the whole Visual project once again from scratch and for some reasons it works now ... why ever. Thanks though.

0 Comments

Oliver

Contact us