Matlab include files giving compilation errors

조회 수: 1 (최근 30일)
Emmanouil Grigoriou
Emmanouil Grigoriou 2021년 8월 14일
답변: Pratyush 2024년 5월 22일
Hello,
I have seen many related questions but no one could answer my case I think.
I'm trying to call the Matlab Engine in a cpp code.
I includes the header files in the code and I made the following simple makefile:
Test: Test.cpp
g++ -g Test.cpp -I/matlabroot/extern/include/ -L/matlabroot/extern/bin/maci64/ -lMatlabDataArray -lMatlabEngine -o Test
However the compilation fails. I get a lot of errors and warnings that seem to suggest that the matlab files contain mistakes?
For example I get errors like this:
/matlabroot/extern/include/MatlabDataArray/GetArrayType.hpp:50:61: error: a space is required between consecutive right angle brackets (use '> >')
template<> struct GetArrayType<std::complex<uint16_t>> { static const ArrayType type = ArrayType::COMPLEX_UINT16; };
In that case it was resolved by changing the Conformance Mode parameter in Visual Studio but I'm using Mac and I don't know how I should modify my makefile. I couldn't find much information about what the conformance mode actually means.
Also it's worth noting that the compilation works fine on Matlab with the command mex. However I plan to add more libraries to my cpp code and I don't think I can include them from Matlab.
Btw, I'm a physics student and I have very little background in these matters so please excuse me if I'm doing some obvious mistake.

답변 (1개)

Pratyush
Pratyush 2024년 5월 22일
Hi Emmanouil,
To resolve the compilation errors you're facing when calling the Matlab Engine in C++ on a Mac, you should specify the C++ standard version (C++11 or newer) in your makefile. This is because the errors suggest compatibility issues with older C++ standards, which require a space between consecutive right angle brackets in template declarations—a requirement removed in C++11 onwards. Update your makefile to include the '-std=c++11' flag (or a later standard if necessary) with 'g++' to ensure compatibility with the Matlab headers. Here's the updated line for your makefile:
g++ -std=c++11 -g Test.cpp -I/matlabroot/extern/include/ -L/matlabroot/extern/bin/maci64/ -lMatlabDataArray -lMatlabEngine -o Test
This adjustment directs 'g++' to compile your code using the C++11 standard, potentially resolving the syntax issues related to template declarations. Adjust the standard ('-std=c++14', '-std=c++17', etc.) as needed based on your code and the Matlab headers' requirements.

카테고리

Help CenterFile Exchange에서 Call C++ from MATLAB에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by