How to get s-function builder to generate c++ style cpp files for compilation with object support?

1 回表示 (過去 30 日間)
To whom it may concern,
I am having trouble using the s-function builder application to build a mex file for use in simulink. I wish to include a class definition and header similar to that seen in the included in the included example permutation (found here open_system('sfbuilder_permutation')). This example builds fine with no problems on my computer (windows 10, Matlab R2017B, visual studio 2017 c/c++ compiler).
The problem is that when I build even the simplest class, and link it, I get the following error: c:\scratch\working code projects\simulink\blarg2\BLARG2.hpp(1): error C2061: syntax error: identifier 'BLARG2'
Without trying to lead the witness, this appears to be an error thrown by Visual Studio not recognising the identifier "class". It is parsing the files as if they were c files.
I can remedy this error by manually taking the output .c and .h files, renaming them as .cpp and .hpp files and compiling using mex from the command window. Howcome the matlab example permutation generates the correct .cpp and .hpp files (see below)?
I have included a very simple example, where only only the header for the class BLARG2 is being included, and an object is not even instantiated and pointed to by pWork. Any thoughts why this is happening?
Thank you in advance,
Steve

回答 (2 件)

Enrique Marti
Enrique Marti 2018 年 3 月 1 日
編集済み: Enrique Marti 2018 年 3 月 1 日
You can change that in the Model Configuration Parameters of the parent Simulink model. In Code Generation section, change Language from C to C++.
After that, your S-Function builder will generate hpp/cpp files.

Muhammad HAMZA
Muhammad HAMZA 2019 年 1 月 21 日
編集済み: Muhammad HAMZA 2019 年 1 月 21 日
i have this issue while building "s-function builder" kindly provide expert openion
C:\s_func_calc_power.c not found; check that you are in the correct current folder, and check the spelling of 'C:\s_func_calc_power.c'.

製品

Community Treasure Hunt

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

Start Hunting!

Translated by