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

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

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 10 Jun 2022
Edited: MathWorks Support Team on 10 Jun 2022
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).
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:MEX-file compilation, MATLAB Compiler and MATLAB Compiler SDK:https://www.mathworks.com/support/bugreports/1487958
Simulink Coder:https://www.mathworks.com/support/bugreports/1558084
Simulink Real-Time:https://www.mathworks.com/support/bugreports/1558109
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.
  5 Comments
Stephan
Stephan on 29 Sep 2020
If you have multiple SDKs installed, you can easily choose an old SDK for Simulink Realtime. Simply add the desired SDK version to the argument list in the file C:\Program Files\MATLAB\R2020a\toolbox\slrt\slrt\slrt_setup_for_visual32.m:
args.mexOpts.batFileArgs = 'x86 10.0.16299.0';
Matlab must be restarted after the file has been modified and the folders slprj and *_slrt_rtw must be deleted once.

Sign in to comment.

More Answers (6)

Timothy
Timothy on 11 Dec 2019
I have a question about step 5. As of 12/11/2019, "VC++ 2017 version 15.9 v14.16" is listed as "latest v141 tools" so should we choose the option indicated as "latest v141 tools" or "VC++ 2017 version 15.8 v14.15" regardless of whether it is indicated as "latest v141 tools".

Sabine
Sabine on 4 Mar 2022
Hi, I'm using R2018a on Windows 10 with VS2017 and ran into an issue. I can compile the timestwo.c, but the compiler does require me to install Windows 10 SDK (10.0.17763.0), otherwise it will not work. The compiler needs Visual C++ tools for CMake, which is dependent on this version of the SDK. Removing this version of the SDK or the whole Visual C++ tools is therefore not possible. However, I run into the indicated error (Unable to load DLL dependency: kernel32.dll.GetFileSizeEx) when loading the application. Any ideas on how to solve/avoid this issue? Thank you!
  1 Comment
Sebastian Kammer
Sebastian Kammer on 4 Mar 2022
Hi Sabine, this is another known issue related to which particular version of Windows 10 SDK is installed. Please see the following post for the solution:

Sign in to comment.


Florian Löcken
Florian Löcken on 3 Nov 2017
Hello, I followed all of your instructions. Everything works fine, if I set the environment variable "'VCCMD_START_DIR','%cd%'" at the start of Matlab. At point seven: The first two examples build without any problems. If I use an example with Simulink functions from the speedgoat library, it means:
Unable to run 'rtwmakecfg' file in directory: 'C:\Program Files\MATLAB\R2017b\toolbox\rtw\targets\xpc\target\build\xpcblocks\thirdpartydrivers\sg_blocks\can' due to error: 'Can't extract compiler version number'
Caused by:
Can't extract compiler version number
I'll use the Matlab Version 2017b and this Compiler:
CompilerConfiguration with properties:
Name: 'Microsoft Visual C++ 2017 (C)'
Manufacturer: 'Microsoft'
Language: 'C'
Version: '15.0'
Location: 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\'
ShortName: 'MSVC150'
Priority: 'B7'
Details: [1×1 mex.CompilerConfigurationDetails]
LinkerName: 'link'
LinkerVersion: ''
MexOpt: 'C:\Users\root\AppData\Roaming\MathWorks\MATLAB\R2017b\mex_C_win64.xml'
Maybe you have an idea how to fix this problem.
  1 Comment
Sebastian
Sebastian on 17 Nov 2017
Edited: MathWorks Support Team on 29 Jun 2021
This error message turns out to be triggered by an issue in the Speedgoat library. While Speedgoat will fix it for a future version, there seems to be an easy way to work around the issue.
Although the Note in step 7 above doesn't mention R2017b, please close your MATLAB, try to remove the HostEnvSettings.xml file, then restart MATLAB und finally re-do the "mex -setup" to point MATLAB to your Visual Studio.
Are you now able to successfully build your model? If you still face any issues, please reach out to the Technical Support team and refer to this Answers thread.

Sign in to comment.


Phillip Siefkas
Phillip Siefkas on 16 Mar 2018
Running ver2017b on Windows 10 and VS 2017 Pro. followed the above direction (bug fixes say their not required for 2017b so I didn't run them) and 'mex -v timestwo.c' completes successfully. But I can't create a boot floppy (3.5" 1.44M) to setup my target computer. it creates BOOTSECT.RTT and then fails "Creation of Simulink Real-Time boot disk failed. Format and Try again" I've formatted the disk verified that its writable and has no bad sectors.
  1 Comment
Phillip Siefkas
Phillip Siefkas on 19 Mar 2018
AS it turns out the new RT kernel is larger than a 1.44MB floppy drive. so unless you have a 2.88MB 3.5" floppy you'll need to move to a different boot option. I used a 4GB USB stick and it seems to be working fine.

Sign in to comment.


Timothy
Timothy on 15 Sep 2021
I followed these instructions and had success with one Windows 10 machine in December 2019. I have been trying to setup another host machine for Simulink Real Time and these instructions did not work. It turned out that the Windows 10 SDK was not installing correctly. I believe that it is due to the same issue described here (Visual Studio 2017 Installer Stuck at Win10SDK - How to fix (ryadel.com)), but I was able to fix it by uninstalling the Windows 10 SDK, then restarting the Visual Studio Installer using the "Run as Administrator" option and re-installing it, then following the remaining instructions on this page. Something may have changed in terms of security policies in the last year or two, just something to be aware of if you are getting stuck.
tl;dr - Start Visual Studio Installer with "Run as Administrator" to avoid a potential issue with the Windows 10 SDK installation.
  1 Comment
Timothy
Timothy on 15 Sep 2021
Edited: Timothy on 15 Sep 2021
Also, to help others that are troubleshooting, using 'mex -v -setup' allowed me to track this issue down since I could see that some components were detected and some were not and where MATLAB was looking for them.
If my suggestion does not work for you, you can also try installing the SDK individually by downloading it from Microsoft (Windows SDK archive - Windows app development (microsoft.com)). Again, use "Run as Administrator".

Sign in to comment.


Santiago Vera Rendon
Santiago Vera Rendon on 18 Oct 2021
Using Ver 2018a and Windows 10 I can compile the timestwo.c. But when I try to create a S-Function, I have the problem:
An installed compiler was not detected. Certain simulation modes, as well as host-based coder builds require that a compiler be installed. Please install one of the supported compilers for this release as listed at:
  3 Comments
Santiago Vera Rendon
Santiago Vera Rendon on 20 Oct 2021
Is it needed? I have install the MinGW compiler and it is works.. I can generate a S-Function, but when I had only Visual Studio I could not generate it.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!