MATLAB Answers

How to setup MATLAB-Compiler to use MSVC2017 Build Tools

182 views (last 30 days)
I was able to sucessfully setup a system using the MATLAB 2018a compiler with Visual Studio 2017 Professional. However on another machine I only run the Visual Stiudio 2017 Build Tools which have all the files needed to compile but only lack the IDE. It seems this compiler is not yet supported by the MATLAB compiler. Is there a way / patch that allows usage of the build tools?
Thanks in advance!

Accepted Answer

Stanislav Tereschenko
Stanislav Tereschenko on 6 Oct 2018
Edited: Stanislav Tereschenko on 8 Oct 2018
I had the same problem to configure the C++ compiler provided by MSVC 2017 build tools with MATLAB R2018b. The solution was quite simple. If you look inside the file located here:
you will see, that MATLAB uses the entries in the registry to search for installed MSVC compilers. Therefore I only added a text entry to
with the name "15.0" and value "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools". After adding this entry, restart MATLAB and repeat the configuration of the mex compiler.
You can use the attached file to add this entry to the registry.
Best Regards!

Sign in to comment.

More Answers (2)

Robert on 12 Jun 2019
Edited: Robert on 12 Jun 2019
R2017b could not find the compiler. Had installed VS Community earlier, then installed VS Pro then removed Community. Needed to manualy change the registry entry referenced above to
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\
  1 Comment
Karl Erik Thoresen
Karl Erik Thoresen on 28 Dec 2019
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\

Sign in to comment.

Simon Weßel
Simon Weßel on 23 Mar 2020
Do you know a workflow to integrate the build tools of the current Visual Studio version (2019) into MATLAB/Simulink?
  1 Comment
Bram De Cooman
Bram De Cooman on 25 Mar 2020
I was able to use the build tools of Visual Studio 2019 by changing
as follows:
  • Locate the part in the xml file within the 'locationFinder' tags (including subtags named VCROOT,SDKROOT,etc.)
  • Within some of these subtags you will notice 3 blocks surrounded by 'and' tags like here:
<envVarExists name="ProgramFiles(x86)" />
<fileExists name="$$\Microsoft Visual Studio\Installer\vswhere.exe" />
<cmdReturns name="&quot;$$\\vswhere.exe&quot; -version &quot;[16.0,17.0)&quot; -products Microsoft.VisualStudio.Product.Enterprise -property installationPath -format value" />
<cmdReturns name="set &quot;vcroot=$$&quot;&amp;for /f &quot;delims= &quot; %a in ('type &quot;$$\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt&quot;') do @if exist &quot;$$\VC\Tools\MSVC\%a\bin\HostX64\x64\cl.exe&quot; call echo %vcroot%" />
  • Each of these blocks tries to find the installation path of Visual Studio 2019 Enterprise, Professional or Community edition. Hence, we will copy such a block and replace Microsoft.VisualStudio.Product.X by Microsoft.VisualStudio.Product.BuildTools. Note that although the blocks under different subtags look similar, each block will be slightly different, so make sure to copy the correct blocks!
  • Leave the subtags without 'and' tags alone, these correspond to registry entries that should already be set up fine as is (provided the BuildTools are correctly installed)
  • Save the file (might need administrator privileges to do so) and relaunch Matlab. If you now type
mex -setup cpp
The Microsoft Visual C++ 2019 compiler will show up correctly.
I had no further issues with using the compiler after this procedure and I hope Matlab will provide native support for this in future versions!

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!