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

2 次查看(过去 30 天)
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 中查找有关 Deployment, Integration, and Supported Hardware 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by