Error with Matlab Engine/Data API for C++ (EDIT: Resolved)
조회 수: 12 (최근 30일)
이전 댓글 표시
I am attempting to write some simple test programs using Matlab Engine for C++. I was able to get it working fine yesterday, until I updated from R2019a Update 1 to R2019a Update 2. Ever since then, the files for Matlab Engine for C++ have been causing compiler errors. Whenever I write a program that includes the files "MatlabEngine.hpp" and/or "MatlabDataArray.hpp", I get the following errors:
Error C2760 syntax error: unexpected token 'identifier', expected 'expression' C:\Program Files\MATLAB\R2019a\extern\include\MatlabDataArray\ArrayFactory.hpp 164
Error C2760 syntax error: unexpected token 'identifier', expected 'expression' C:\Program Files\MATLAB\R2019a\extern\include\MatlabDataArray\ArrayFactory.hpp 219
Error C2760 syntax error: unexpected token 'identifier', expected 'expression' C:\Program Files\MATLAB\R2019a\extern\include\MatlabDataArray\ArrayFactory.hpp 552
Error C2760 syntax error: unexpected token 'identifier', expected 'expression' C:\Program Files\MATLAB\R2019a\extern\include\MatlabDataArray\ArrayFactory.hpp 624
I am compiling using Visual Studio 2019, and am using a trial license version of Matlab. I am compiling and running on a Windows 10 computer. These errors occur even with this simple test program:
#include <iostream>
#include "MatlabEngine.hpp"
#include "MatlabDataArray.hpp"
int main(){
std::cout << "Hello World!\n\r";
return 0;
}
I have all the necessary folders/libraries in my path and project settings. It is always the same 4 errors. Does anyone have any idea what might be causing this? I have tried re-installing Matlab and Visual Studio, but nothing seems to work.
EDIT :
Found the problem. I changed the setting Project->Properties->C/C++->Language->Conformance Mode from "Yes" to "No", and that fixed the error.
댓글 수: 2
Alan Frankel
2020년 6월 17일
This should only happen with Visual Studio 2019 Community Edition, not Professional, and it should not happen with earlier versions of Visual Studio. Could you please confirm that you are using Visual Studio 2019 Community Edition?
답변 (1개)
Alan Frankel
2020년 6월 17일
편집: Alan Frankel
2020년 6월 17일
Setting Conformance mode to No will work around a compiler build issue seen in VS 2019 Community Edition with MATLAB R2018b through R2020a, in which several lines in extern\include\MatlabDataArray\ArrayFactory.hpp will trigger error C2760. Note that with mbuild, Conformance mode is set to No by default. Alternatively, particularly if Conformance mode = Yes is desired, the error can be fixed by inserting the keyword typename before instances of the strings impl::ArrayFactoryImpl and impl::ArrayImpl on those lines. The compiler error is not seen in VS 2019 Professional, VS 2017 Professional, or VS 2017 Community Edition. See also How do I build a driver application for a C++ MATLAB Data API Shared Library using Microsoft Visual Studio?
댓글 수: 4
Alan Frankel
2020년 9월 8일
Gavin was describing a compiler issue. You are describing a different issue, which occurs at runtime. Have you seen this post?
Alexander van Zyl
2020년 10월 20일
편집: Alexander van Zyl
2020년 10월 20일
I am having the same issue as @Jacob and I have not been able to fix it.
참고 항목
카테고리
Help Center 및 File Exchange에서 C Shared Library Integration에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!