フィルターのクリア

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

2 ビュー (過去 30 日間)
wahhaj javed
wahhaj javed 2016 年 7 月 29 日
回答済み: Anatoly Khamukhin 2018 年 1 月 25 日
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 Center および File ExchangeCall C++ from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by