필터 지우기
필터 지우기

Errors when compiling C++ file using legacy_code and Microsoft Visual C++ 2017

조회 수: 22 (최근 30일)
Pan Zhao
Pan Zhao 2021년 8월 18일
편집: Pan Zhao 2021년 8월 21일
I am following the steps explained here to integrate a C++ function into my simulink file. I was able to successfully run
legacy_code('sfcn_cmex_generate', def);
to create the C S-function file. However, when I tried to run
legacy_code('compile', def);
I got the following syntax errors related to cstdlib and cmath
C:\Program Files (x86)\Microsoft Visual
Studio\2017\Professional\VC\Tools\MSVC\14.10.25017\include\cstdlib(11): error C2061: syntax error: identifier
'noexcept'
C:\Program Files (x86)\Microsoft Visual
Studio\2017\Professional\VC\Tools\MSVC\14.10.25017\include\cstdlib(11): error C2059: syntax error: ';'
C:\Program Files (x86)\Microsoft Visual
Studio\2017\Professional\VC\Tools\MSVC\14.10.25017\include\cstdlib(12): error C2449: found '{' at file scope
(missing function header?)
C:\Program Files (x86)\Microsoft Visual
Studio\2017\Professional\VC\Tools\MSVC\14.10.25017\include\cstdlib(14): error C2059: syntax error: '}'
C:\Program Files (x86)\Microsoft Visual
Studio\2017\Professional\VC\Tools\MSVC\14.10.25017\include\cstdlib(21): error C2061: syntax error: identifier
'noexcept'
C:\Program Files (x86)\Microsoft Visual
Studio\2017\Professional\VC\Tools\MSVC\14.10.25017\include\cstdlib(21): error C2059: syntax error: ';'
C:\Program Files (x86)\Microsoft Visual
Studio\2017\Professional\VC\Tools\MSVC\14.10.25017\include\cstdlib(22): error C2449: found '{' at file scope
(missing function header?)
C:\Program Files (x86)\Microsoft Visual
Studio\2017\Professional\VC\Tools\MSVC\14.10.25017\include\cstdlib(24): error C2059: syntax error: '}'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.10.25017\include\cmath(9):
error C2061: syntax error: identifier 'noexcept'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.10.25017\include\cmath(9):
error C2059: syntax error: ';'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.10.25017\include\cmath(10):
error C2449: found '{' at file scope (missing function header?)
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.10.25017\include\cmath(15):
error C2059: syntax error: '}'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.10.25017\include\cmath(22):
error C2061: syntax error: identifier 'noexcept'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.10.25017\include\cmath(22):
error C2059: syntax error: ';'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.10.25017\include\cmath(23):
error C2449: found '{' at file scope (missing function header?)
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.10.25017\include\cmath(25):
error C2059: syntax error: '}'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.10.25017\include\cmath(32):
error C2061: syntax error: identifier 'noexcept'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.10.25017\include\cmath(32):
Can anybody help me fix these errors? Thank you very much.
  댓글 수: 2
Ben McMahon
Ben McMahon 2021년 8월 20일
I do not the the specifics of this, as I have never used the legacy code functionality. However I have got similar errors when trying to include C++ files into C code using the embedded coder in Simulink. I would suggest as a starting point try ensuring the coder is set to C++.
From looking at the documentation it seems this can be done in the legacy coder tool using:
def = legacy_code('initialize');
def.Options.language = 'C++';
However this may not be the issue at all. Be intrested to know how you get on.
Pan Zhao
Pan Zhao 2021년 8월 21일
편집: Pan Zhao 2021년 8월 21일
@Ben McMahonThanks very much for your insights. Following your suggestions, I did resolve the errors mentioned above. Some other errors came out, which I believe are not related to compiling. I have explained the new errors in another post: https://www.mathworks.com/matlabcentral/answers/1437819-errors-with-using-legacy_code-to-integrate-c-codes-generated-from-deep-learning-toolbox-using-mkl

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Application Deployment에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by