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

12 vues (au cours des 30 derniers jours)
Pan Zhao
Pan Zhao le 18 Août 2021
Modifié(e) : Pan Zhao le 21 Août 2021
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 commentaires
Ben McMahon
Ben McMahon le 20 Août 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 le 21 Août 2021
Modifié(e) : Pan Zhao le 21 Août 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

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Deployment, Integration, and Supported Hardware dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by