MATLAB: How to build and run the Simulink model in accelerator mode without copying the necessary wrapper files to the model’s directory

simulink

I have a large Simulink model which contains a number of S-functions written in C. Some of these S-functions are inlined with TLC files and wrapper .h and .c files, and the S-functions are set to use TLC when in accelerator mode.
The issue that I have is that the model will not build correctly in accelerator mode, unless copies of the wrapper .c and .h files are located in the same directory as the model. Is there any way to get around this?

Best Answer

When an S-function is configured to be inlined using a TLC file in accelerator mode, the required TLC, .c and .h files must be on the compiler path. By default this is ensured by placing them in the current directory.
There are two workarounds to allow them to not be in the current directory:
1) Normally, the compiler will look at the current directory where the model resides to find these two additional files. When the compiler does not find these files, it produces an error. If you do not want to have to copy these files to each model directory that uses this S-function, you can customize the generated makefile such that the source and include directories have been added. The documentation covering this can be found at the following web address:
<http://www.mathworks.com/help/releases/R2013a/rtw/ug/customizing-template-makefiles.html>
2) The second method involves making a change to the model’s configuration set. In the model, open the configuration parameters window, and go to the “Custom Code” tab on the left. Then, add the directory where the files are located to the “Include directories” dialog window. For more detailed information on how to add include directories, please refer to the following documentation.
<http://www.mathworks.com/help/releases/R2013a/rtw/ref/code-generation-pane-custom-code.html>