How do I set up Microsoft Visual Studio 2017 for SLRT?

248 views (last 30 days)
How do I set up Microsoft Visual Studio 2017 for use with Simulink Real-Time (R2020a and earlier)?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 5 Apr 2023
Edited: MathWorks Support Team on 5 Apr 2023
NOTE:
From MATLAB R2020b, Microsoft Visual Studio is no longer required with Simulink Real-Time.
The toolchain to compile and build real-time applications is shipped with the free-of-charge Simulink Real-Time Target Support Package.
**************************************************
Install Visual Studio 2017 with Windows 10 SDK and VC++ 2017 toolset:
1) Begin installing your edition of Visual Studio 2017 as normal or if you have already installed Visual Studio 2017, run the Visual Studio Installer and skip to step (3) in this section. ​​​
2) Once Visual Studio 2017 is installed, the buttons Update, Launch, and a hamburger menu will appear. ​
3) Click on the hamburger menu and choose Modify. ​​
4) This will bring up the "Modifying" dialog box. 
5) Click on the Individual components tab.
Check the box for Windows 10 SDK, VC++ 2017 toolset (v141 tools) and the following Visual Studio C++ core features.
Windows 10 SDK (10.0.17134.0 or earlier) under SDKs, libraries, and frameworks
VC++ 2017 version 15.8 v14.15 under Compilers, build tools, and runtimes
(latest v141 tools or VC++ 2017 15.8 v14.15 latest v141 tools if the given option is not available).- Visual Studio C++ core features
 under Development Activities.
CAUTION:
 Do not install Windows 10 SDK (10.0.17763.0) or a later version. This is known to cause an error on the target upon loading the application (Unable to load DLL dependency: kernel32.dll.GetFileSizeEx). See the following bug report for more information: https://www.mathworks.com/support/bugreports/details/1890172
Click the Modify button.
6) Visual Studio 2017 will now start adding the necessary components to its installation.
Set up MATLAB and Simulink Real-Time to Detect Visual Studio 2017 Compiler:
1) If using R2016b or R2017a, install patches that will allow MATLAB and Simulink to detect the Visual Studio 2017 compiler. All patches must be installed in the following order:\n
2) Execute the following (note, this will remove all support packages and custom libraries, so they need to be reinstalled or added back to the path): 
rehash toolboxcache
3) Restart MATLAB.
4) Execute
mex -setup
5) ​Select Microsoft Visual C++ 2017 (C)
6) Copy the attached timestwo.c file to an empty directory to make sure that you can mex. Then, execute
mex -v timestwo.c
7) ​If mex works without error, you can now use Simulink Real-Time with the Visual Studio 2017 compiler. If you are using Speedgoat libraries, they can now be installed. Make sure that you install the latest Speedgoat libraries. 
Note:In R2016b and R2017a, do NOT execute "slrtsetCC setup" to select Visual Studio 2017 as the compiler for SLRT because this may create an unusable MEX setup. Only "mex -setup" is required in R2016b and R2017a. If "slrtsetCC setup" has been called, delete the HostEnvSettings.xml file in the directory returned by executing "xpcprefdir" in the Command Window. 
Troubleshooting:If you encounter build issues with your Simulink Real-Time model, check whether you can build with increasingly complex models. For example, begin by
  1. Making the example 'vdp' model fixed-step and building it (check if any Simulink model can be built)
  2. Building the example 'xpcosc' model (check if any Simulink Real-Time model can be built)
  3. Building an example Speedgoat model (if applicable, check if any Speedgoat model can be built)
  4. Finally, building your own model (check if the build issue is model-specific).
This helps narrow down the cause of the issue.
  2 Comments
Diego Kuratli
Diego Kuratli on 6 Apr 2018
The "Visual Studio C++ core features" component seems required too. Therefore, the minimal VS2017 installation should include: * Windows 10 SDK * VC++ 2017 toolset * Visual Studio C++ core features
Sebastian K
Sebastian K on 9 Oct 2018
Hi Viktor. The patches will not work for R2015b. You would need to install one of the supported compilers based on your platform.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!