Trying to initialize matlab shared library in visual studio gives access violation

2 views (last 30 days)
I think I've figured out why there is an access violation. In the header file generated by matlab (calcFunc.h) when the dll was created, all the functions are missing definitions. Since calcFuncInitialize(); does not have a definition, calling it causing an error. I tried including the calcFunc.cpp file in my project but that gave me a linker error saying that there are two functions with the same name. Here is the code in my c++ main function
% bool temp = mclInitializeApplication(NULL, 0);
if (!temp)
{
std::cerr << "could not initialize the application properly"
<< std::endl;
return -1;
}
bool temp2 = calcFuncInitialize();
if (!temp2)
{
std::cerr << "Could not initialize the library properly."
<< std::endl;
return -1;
}
Everything works fine until I try to execute the bool temp2 = calcFuncInitialize(); line where I get the access violation error. How do I go about fixing this?
I used this post to setup visual studio and I'm sure there are no libraries missing. I am using visual studio community 2015 and matlab 2016a. I've also attached the calcFunc.h and calcFunc.cpp files in case they are needed.

Answers (2)

Christian
Christian on 13 Jan 2017
Hi, I also have the same problem with Matlab 2016b and VS2015 for C++ and C.
Do you have any solutions?
Thanks, Christian

Anatoly Khamukhin
Anatoly Khamukhin on 25 Jan 2018
Call
const char *args[] = {"-nojvm"};
const int count = sizeof(args) / sizeof(args[0]);
mclInitializeApplication(args, count))
instead of
mclInitializeApplication(NULL,0)
It solved the same issue for me (Matlab2017 + VS 2015).

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!