Calling matlab from c++

조회 수: 2 (최근 30일)
Yoni Berk
Yoni Berk 2018년 5월 16일
답변: Akshat Dalal 2025년 5월 12일
Hello! I created a simply matlab funcion
function addFunc(a,b)
plot(a,b);
end
and I compiled it to a lib and dll.
#include "stdafx.h"
#include "engine.h"
#include "addFunc.h"
#pragma comment(lib, "libmat.lib")
#pragma comment(lib, "libmx.lib")
#pragma comment(lib, "libmex.lib")
#pragma comment(lib, "libeng.lib")
#pragma comment(lib, "addFunc.lib")
#pragma comment(lib, "mclmcrrt.lib")
So what next? how can I call this function from VS?
Thanks!
  댓글 수: 7
Yoni Berk
Yoni Berk 2018년 5월 17일
Update: I copied the dlls to the project folder and it is "working". But I got initialization error from this section:
// Initialize the MATLAB Compiler Runtime global state
mclInitializeApplication(NULL, 0)
if (!mclInitializeApplication(NULL, 0))
{
std::cerr << "Could not initialize the application properly."
<< std::endl;
return -1;
}
Yoni Berk
Yoni Berk 2018년 5월 17일
Sove this part. I removed the mclInitializeApplication(NULL, 0) line before the if statement. Now I have an error at the library initialization part. It writes me that function or variable 'javaaddpath' is undefined. :\

댓글을 달려면 로그인하십시오.

답변 (1개)

Akshat Dalal
Akshat Dalal 2025년 5월 12일
Hi Yoni,
My understanding is that the error you are facing regarding "that function or variable 'javaaddpath' is undefined" is expected. This is because the generated code probably has some interfacing with MATLAB which is being used to execute MATLAB code on the MATLAB engine. However, since you're trying to create a standalone application with MATLAB, 'javaaddpath' being an inbuild MATLAB function is undefined. You can debug this further to identify where the MATLAB Engine is being exectued and instead use your own custom piece of code. I might be wrong but this is what seems to be the issue.

카테고리

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

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by