Trying to initialize matlab shared library in visual studio gives access violation
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
0 comentarios
Respuestas (2)
Christian
el 13 de En. de 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
el 25 de En. de 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).
0 comentarios
Ver también
Categorías
Más información sobre C Shared Library Integration en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!