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

12 views (last 30 days)
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 Comments
Ben McMahon
Ben McMahon on 20 Aug 2021
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 on 21 Aug 2021
Edited: Pan Zhao on 21 Aug 2021
@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

Sign in to comment.

Answers (0)

Categories

Find more on Deployment, Integration, and Supported Hardware in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!