%% Integrate External C++ Code into a Model Using S-Functions
% This example shows you how to integrate C++ code into a model by using
% S-functions.

%% Open Example Model
% Open the example model |rtwdemo_cpp|.

% Copyright 2019 The MathWorks, Inc.

open_system('rtwdemo_cpp');
%% Configure C++ Compiler
% 1. In the MATLAB Command Window, enter this command:
% 
% |mex -setup|
%
% 2.  When prompted, select a C++ compiler that is installed on your development
% computer.
%% Integrate C++ Code
% You can integrate C++ code into a model by using S-functions.
%
% 1. Prepare the S-function source.
%
% * <matlab:edit(fullfile(matlabroot,'simulink','src','sfun_cppcount_cpp.cpp')); Open sfun_cppcount_cpp.cpp>
% * <matlab:edit(fullfile(matlabroot,'simulink','src','sfun_cppcount_cpp.h')); Open sfun_cppcount_cpp.h>  
%
% 2. Open the *Simulink Coder* or *Embedded Coder* app. 
%
% 3. Configure S-function source files and folders. Open the Model 
% Configuration Parameter dialog box, navigate to the *Code Generation > Custom 
% Code* pane, and add the S-function source files and |include| folders.
%
% 4. Inline the S-function to eliminate overhead of S-functions in the generated
% code. 
%
% <matlab:edit(fullfile(matlabroot,'toolbox','simulink','blocks','tlc_c','sfun_cppcount_cpp.tlc')); Open sfun_cppcount_cpp.tlc>                          
%% Configure Model for C++ Code Generation
% Set model configuration parameter *Language* to |C++|.
%% Generate and review code.
% Generate and reviw the C++ code.  
%% Related Topics
%
% * <docid:rtw_ug.brlpg7w-1 Programming Language Considerations>
% * <docid:rtw_ug.brlpg7w-3 C++ Language Support Limitations>