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

조회 수: 3 (최근 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.

답변 (2개)

Christian
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
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).

카테고리

Help CenterFile Exchange에서 C Shared Library Integration에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by