MATLAB Answers

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

조회 수: 675(최근 30일)
How do I set up Microsoft Visual Studio 2017 for use with Simulink Real-Time?

채택된 답변

MathWorks Support Team
편집: MathWorks Support Team 24 Jan 2020
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:
Simulink Coder:
Simulink Real-Time:
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.

  댓글 수: 4

표시 이전 댓글 수: 1
Viktor Gustavsson
Viktor Gustavsson 19 Jul 2018
Do you know if the patches linked for the matlab and simulink setups also work for R2015b?
Sebastian Kammer
Sebastian Kammer 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.
EP
EP 30 Oct 2018
Commenting just in case someone else has the same issue I did: I installed only Visual Studio 2017 build tools (didn't want the entire IDE) and MATLAB was unable to find the compiler. A small registry tweak as suggested in another MATLAB Answer fixed the issue:
https://www.mathworks.com/matlabcentral/answers/412396-how-to-setup-matlab-compiler-to-use-msvc2017-build-tools

로그인 to comment.

추가 답변(3개)

Florian Löcken
Florian Löcken 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

Sebastian
Sebastian 17 Nov 2017
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.

로그인 to comment.


Phillip Siefkas
Phillip Siefkas 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

Phillip Siefkas
Phillip Siefkas 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.

로그인 to comment.


Timothy
Timothy 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".

  댓글 수: 0

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.


Translated by