Could not initialize the library properly

7 views (last 30 days)
Ali Mustafa
Ali Mustafa on 8 Sep 2013
I have a small MATLAB function "function a = addmatrix(a1,a2) a = a1+a2;". I've created a project, added the function file, built and generated the .h, .lib and .dll files. Then I've added them to a new visual studio project as files, added the library directory to the Additional Libraries Directories. Also, I did the setup of MCR and got a copy from the include and lib files in the extern folder and added them to the visual studio project and added the paths to the Additional Include Directories and Additional Libraries Directories. I added also the lib files in the MCR lib folder to the Additional Libraries. I got no syntax errors, but when I debug the application it always couldn't initialize the library and return false.
This is my code:
//--------------------------------------------------------------------
if (!mclInitializeApplication(NULL,0))
{
std::cerr << "Could not initialize the application properly."<< std::endl;
return;
}
// Initialize the test library
if(!libtestInitialize())
{
std::cerr << "Could not initialize the library properly."<< std::endl;
return;
}
double r1[] = {1,3,5,7};
double r2[] = {2,4,6,8};
mwArray mwA1(1, 4, mxDOUBLE_CLASS);
mwArray mwA2(1, 4, mxDOUBLE_CLASS);
mwA1.SetData(r1, 4);
mwA2.SetData(r2, 4);
int nargout = 1;
mwArray mwA;
addmatrix(nargout,mwA,mwA1,mwA2);
double* o = new double[4];
mwA.GetData(o,4);
delete []o;
mclTerminateApplication();
libtestTerminate();
//-----------------------------------------------------------------
I cannot figure out where the problem. Is it in the lib or in the settings and properties of the project, or in the code.
I'm using MATLAB 2010a x86 with MCR 717 and Microsoft Visual Studio 2008 under windows 8 32-bit.
I appreciate your help.
Thanks

Answers (2)

Ali Mustafa
Ali Mustafa on 8 Sep 2013
I got the answer. The MATLAB version should match MCR version. So, in order to work with MCR 717, I have to build the MATLAB function using MATLAB 2012a. This solves the problem

Image Analyst
Image Analyst on 8 Sep 2013

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!