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

4 views (last 30 days)
Stephen Warwick
Stephen Warwick on 11 Jan 2018
Edited: Muhammad HAMZA on 21 Jan 2019
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,

Answers (2)

Enrique Marti
Enrique Marti on 1 Mar 2018
Edited: Enrique Marti on 1 Mar 2018
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 on 21 Jan 2019
Edited: Muhammad HAMZA on 21 Jan 2019
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!