Matlab include files giving compilation errors
1 次查看(过去 30 天)
显示 更早的评论
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; };
I think a similar problem was met in this thread: https://www.mathworks.com/matlabcentral/answers/463726-error-with-matlab-engine-data-api-for-c-edit-resolved
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.
0 个评论
回答(1 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Call C++ from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!