Can I use Microsoft Visual Studio 2017 with MATLAB R2017a or R2016b?

156 views (last 30 days)
Can I use Microsoft Visual Studio 2017 compilers with MATLAB R2017a or R2016b?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 5 Feb 2019
Edited: MathWorks Support Team on 5 Feb 2019
MATLAB R2017b supports Microsoft Visual Studio 2017. But if you hit the "NMAKE: fatal error U1052", then see the following post:
Support for Microsoft Visual Studio 2017 can be added to MATLAB R2017a or MATLAB R2016b through a patch. Support can be added for the following features:
  • MEX-file compilation
  • MATLAB Compiler
  • MATLAB Compiler SDK
  • Simulink Coder
  • Simulink Real-Time
  • Audio System Toolbox
Depending on which products you are using, install the patches attached to the following Bug Reports:
MEX-file compilation, MATLAB Compiler and MATLAB Compiler SDK:
Simulink Coder:
Simulink Real-Time:
Audio System Toolbox:
Note: Support for Visual Studio 2017 is not currently available for releases older than MATLAB R2016b.

Sign in to comment.

More Answers (5)

Zeyu Ren
Zeyu Ren on 13 Oct 2017
For me, I use Matlab 2017b, there is no problem for command "mex -setup" and "slrtgetCC", i can always find my installed Visual Studio 2017 C++ Compiler. But the problem is, when i open the example model 'vdp', i still can not build it. The error(s) are following:
_ *Validation error(s):
_ *### Validating other build tools ...
Unable to locate build tool "Microsoft Visual C Compiler": cl
Unable to locate build tool "Microsoft Visual C Linker": link
Unable to locate build tool "Microsoft Visual C++ Compiler": cl
Unable to locate build tool "Microsoft Visual C++ Linker": link
Unable to locate build tool "Microsoft Visual C/C++ Archiver": lib
Unable to locate build tool "NMAKE Utility": nmake*_*_
It seems the simulink still can not find the 2017 Visual Studio C++ Compiler.
I really do not know what to do.

Sign in to comment.

Rashmi singh
Rashmi singh on 30 Aug 2017
Edited: Walter Roberson on 30 Aug 2017
patch did not work for me. MATLAB 2017a 64 bit, on Windows 10 with Visual Studio 2017 Community. After patching, mex -setup still does not find any compiler.
Carlos Ricolfe-Viala
Carlos Ricolfe-Viala on 3 Apr 2018
Have you fixed this issue? My Matlab 2017b neither detects Microsoft Visual Studio 2017 Community. :( How can I fix it?

Sign in to comment.

Gabriele Trifiletti
Gabriele Trifiletti on 5 Oct 2017
does this patch work for r2015b 32 bit version of matlab?
lebarsfa on 4 Feb 2018
I made my own adaptations to make R2013a (32 bit) work with Visual Studio 2013, 2015 and 2017 (see Note that this might not work directly depending on the Visual Studio edition (Pro, Community, etc.), update version, etc. and if Visual Studio or MATLAB are not in default installation folders (in those cases you will need to tweak manually the files to match your configuration). This is especially difficult for Visual Studio 2017, that has many changes in its default path, I ran manually those kinds of commands :
setx VS150COMNTOOLS "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Enterprise\Common7\Tools" /m
reg add HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\SxS\VS7 /v "15.0" /d "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Enterprise\\" /f
to make it similar to previous versions, however some version numbers of the tools and SDK are currently hardcoded (my update version of Visual Studio 2017 was probably 15.1, installed on Windows 10 v1709 64 bit (change the "%ProgramFiles(x86)%" to "%ProgramFiles%" if using a 32 bit version of Windows)...
I did not make an adaptation for R2015b (32 bit), the adaptation files look significantly different, but it should be probably possible to make the same kind of adaptation by looking at C:\Program Files (x86)\MATLAB\R2015b\bin\win32\mexopts and adding the right files with values inspired from the one used in R2013a (from the adaptation I provide) and R2017b (that works out of the box for me with Visual Studio 2017)...
Also, be sure to install all the necessary "workloads" and "components" for Visual Studio 2017, e.g. here is the command I used :
vs_enterprise.exe --passive --norestart --wait --includeRecommended --add Microsoft.VisualStudio.Component.CoreEditor --add Microsoft.VisualStudio.Workload.NativeDesktop --add Microsoft.VisualStudio.Workload.ManagedDesktop --add Microsoft.VisualStudio.ComponentGroup.NativeDesktop.WinXP --add Microsoft.VisualStudio.Component.WinXP --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --add Microsoft.VisualStudio.Workload.NativeCrossPlat --add Microsoft.VisualStudio.Component.VC.ATLMFC --add Microsoft.VisualStudio.Component.VC.CLI.Support --add Microsoft.VisualStudio.Component.VC.Modules.x86.x64 --add Microsoft.VisualStudio.Workload.Python --remove Microsoft.Component.CookiecutterTools --remove Microsoft.Component.PythonTools.Web --remove Component.CPython3.x64 --add Microsoft.VisualStudio.Component.Graphics --add Component.GitHub.VisualStudio --add Microsoft.VisualStudio.Component.JavaScript.Diagnostics --add Microsoft.VisualStudio.Component.JavaScript.TypeScript --add Microsoft.VisualStudio.Component.TestTools.Core --add Microsoft.VisualStudio.Component.PowerShell.Tools
and double-check that Visual Studio 2017 is able to build and run simple C and C++ programs after installation.

Sign in to comment.

Jeff Burch
Jeff Burch on 6 Mar 2018
I have a related question. I routinely build a C++ DLL with VS2017 and call it from Matlab R2017a. My problem comes when using VS2017 to debug the DLL on a Windows 10 machine. I can't get the debugger's "attach" to work properly. It complains that it can't find "Matlab.exe" in the process list (even though I have it running). Note that I have verified using the proces explorer that my desired "debug version" of my DLL was properly loaded by Matlab.
Note that this worked perfectly with VS2012 and an earlier version of Matlab on a Windows 7 machine.
The full VS2017 error message is:
Unable to attach. Proces 'C:\Program Files\MATLAB\R2017a\bin\matlab.exe' is not running on '<my machine name here>'. Refresh the process list before attempting another attach.
  1 Comment
lebarsfa on 8 Mar 2018
With MATLAB 2017b, I noticed in Process Explorer that the main MATLAB process full path is 'C:\Program Files\MATLAB\R2017b\bin\win64\MATLAB.exe'. So when I see your error message, I wonder if you should try with 'C:\Program Files\MATLAB\R2017a\bin\win64\MATLAB.exe' at some point when you attach... Also, you might need to try with right-click "Run as administrator" when you launch MATLAB and Visual Studio, also try to login as a local administrator account instead of a Microsoft account on Windows 10 if you were using that... I just tested in that conditions and I was able to hit a breakpoint in my DLL code, with my DLL being loaded in MATLAB using loadlibrary (and in Visual Studio I just clicked on the MATLAB.exe process in the Attach to Process list, that indicates 'C:\Program Files\MATLAB\R2017b\bin\win64\MATLAB.exe' when I pause the mouse on it).

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!