MATLAB Answers

3

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

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

6 Answers

Answer by MathWorks Support Team on 5 Feb 2019 at 5:00
Edited by MathWorks Support Team on 5 Feb 2019 at 19:42
 Accepted Answer

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.

  19 Comments

Hello,
For me it works, the added file allow mex -setup to detect Visual Studio 2017.
However, when I try to compile a mex file I got:
LINK : error LNK2001: unresolved external symbol mexfilerequiredapiversion Any idea ?
TK,
Benjamin

Sign in to comment.


Answer by 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.

  3 Comments

Check your error log , before that error is there:
**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.4.3
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x86'
Microsoft (R) Program Maintenance Utility Version 14.11.25547.0
Copyright (C) Microsoft Corporation. All rights reserved.
NMAKE : fatal error U1052: file 'model.mk' not found
Stop.
The make command returned an error of 2
If there is, the problem is that vcvarsall.bat changes the working directory when called so the .mk file isn't where you think. Also VS2017 changes how to find Visual studio so that's why matlab decides it doesn't exist even though it knows where it is.
Is there any suggestion for this issue?
https://cn.mathworks.com/support/bugreports/1649009

Sign in to comment.


Answer by Rashmi singh on 30 Aug 2017
Edited by 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.

  6 Comments

I have the same issue that Matlab R2017b cannot find Visual Studio 2017.
same issue MATLAB R2017a and MATLAB R2017b both cant find VIsual studio professional 2017,, windows 10
Have you fixed this issue? My Matlab 2017b neither detects Microsoft Visual Studio 2017 Community. :( How can I fix it?

Sign in to comment.


Answer by Gabriele Trifiletti on 5 Oct 2017

does this patch work for r2015b 32 bit version of matlab?

  2 Comments

No.
"Note: Support for Visual Studio 2017 is not currently available for releases older than MATLAB R2016b."
Using info from http://kaba.hilvi.org/homepage/blog/vs2013_in_matlab_2013/vs_2013_in_matlab_2013.htm, I made my own adaptations to make R2013a (32 bit) work with Visual Studio 2013, 2015 and 2017 (see vs2013_vs2015_vs2017_support.zip). 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.


Answer by 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

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.


Answer by Zeinab Beydoun on 10 Sep 2018

I think you have to open Matlab with Admin rights too.

  0 Comments

Sign in to comment.