Trying to initialize matlab shared library in visual studio gives access violation
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Christian
2017-1-13
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
2018-1-25
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 C Shared Library Integration 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!