Getting Compile to work with Visual Studio 2017 Community Edition



The new Visual Studio is out since a week and I tried to get it to work with Mathematica (versions 11.0 and 11.1). However, the usual tricks for working with a new VS version fail here.

Related seems to be the remark made on Microsoft's MSDN blog:

Since we have removed the VS150COMNTOOLS registry key to support the new world where multiple VS instances of the same product can be installed side-by-side on the same machine, we know that many build systems and tools have relied on this in the past and the new options are not an identical replacement. We are actively working with library developers and others with builds that depend on the VC++ compiler tools, and we are open to further feedback to help refine and improve upon the solutions mentioned above. Please share any feedback you have in the comments or feel free to send more detailed suggestions to

Anyone tried VS 2017 and succeeded in getting it to work with Compile?

Sjoerd C. de Vries

Posted 2017-03-14T21:16:31.303

Reputation: 63 549

CCompilerDriver does not support VS2017. I think the changes in the new VS (as you mentioned) were drastic enough where there will be need to be changes from Mathematica's end to at least easily get them to work together. – ktm – 2017-03-15T13:16:09.737

@user6014 I'm not too sure of that. It looks like the changes concern only things as path finding/setting. That should be doable or are you aware of any other fundamental issues? – Sjoerd C. de Vries – 2017-03-15T13:20:31.443

Either way, could you mail Wolfram and ask them to fix this? – Szabolcs – 2017-03-15T16:48:29.777

@Szabolcs OK, mail has been sent. – Sjoerd C. de Vries – 2017-03-15T20:48:17.603

If you do solve it, please post an answer. I too am going to need this soon ... – Szabolcs – 2017-03-15T20:59:49.527

1@Szabolcs I tried a few things but they didn't work. I guess installing an older VS version is the current workaround, but I don't like to have several massive installations in parallel. – Sjoerd C. de Vries – 2017-03-15T21:40:26.263


Temporary workaround: To use a C++ compiler with Mathematica, it seems to be sufficient to install this (no GUI needed, safe to uncheck all components at installation). Take the 2015 version of course. It seems to coexist just fine with VS2017, so you can have it installed until Mathematica will work with VS2017.

– Szabolcs – 2017-03-22T10:00:26.367

2A small correction: It is not safe to uncheck all components. If you do not already have a Windows SDK installed, do check this component during the installation of the build tools. In my case everything worked because I already had it installed. – Szabolcs – 2017-04-03T11:32:56.890

@Szabolcs after installing the C++ compiler tools, did you have to modify their directory location? Or simply installing them was good enough? I have recently installed VS 2017, and my Mathematica still gives compile errors. Even after downloading the VS 2015 tools, I still get: "A library could not be generated from the compiled function". Upon typing GetEnviornment[], it shows it's using the VS140COMNTOOLS, So it appears the Mathematica should be able to compile. This has left me really scratching my head. I also installed the latest Windows SDK when installing VS2017. – Luca Pontiggia – 2017-06-01T08:07:54.617

@LucaPontiggia VS2017 is not compatible with Mathematica 11.1. The tools I linked to work, no configuration needed after install. What version of Mathematica do you have? – Szabolcs – 2017-06-01T08:15:03.197

Well I have Mathematica 11.0, which was mentioned in the question. I just understood the tools you linked were a work around this problem - until Mathematica fixes it. If they are indeed incompatible, I guess I will have to uninstall and install VS2015 – Luca Pontiggia – 2017-06-01T08:20:40.067

@LucaPontiggia It's not a workaround. Mathematica is compatible with some compilers, not with others. The one I linked to is the smallest set of tools you can use. You do not need to install the full VS2015, if you only need it for Mathematica. – Szabolcs – 2017-06-02T07:21:39.853



Since version 11.2.0, the CCompilerDriver package has been updated and supports Microsoft Visual Studio 2017.

As mentioned in the question, starting with VS2017 the VSXXXCOMNTOOLS registry keys or environment variables are no longer provided, so a new mechanism was needed so that the compiler installation can be detected. This is based on Microsoft's vswhere locator tool.

If a full VS installation with the IDE is not needed, the Visual Studio Build Tools can also be used.


Posted 2017-03-14T21:16:31.303

Reputation: 24 492

Works flawlessly for me. Thanks! Is there something that users of older Mathematica version can do, using vswhere? – Sjoerd C. de Vries – 2017-11-19T15:55:14.117

Could please explicitly point out the minimum components of Visual Studio 2017 that need ticking when installing? – Αλέξανδρος Ζεγγ – 2018-03-16T07:00:33.950

@ΑλέξανδροςΖεγγ I would try to only install the build tools: I haven't tried this myself though. I still use the 2015 one.

– Szabolcs – 2018-04-01T17:50:54.977

@SjoerdC.deVries You got it working just with the updated 11.3 or did additional workaround? Please, edit your question with an UPDATE to include the version of your code with the output f using Needs["CCompilerDriver`"] CCompilers[] . I will like to see if your compiler recognizes the VS 2017 and how a compiled code is outputed. – Jose Enrique Calderon – 2018-05-01T13:27:45.517

@Szabolcs I installed the built tools and made no difference. – Jose Enrique Calderon – 2018-05-01T13:30:46.150

@JoseECalderon I did not do anything in addition to just installing 11.3. It just works. {{"Name" -> "Visual Studio", "Compiler" -> CCompilerDriver`VisualStudioCompiler`VisualStudioCompiler, "CompilerInstallation" -> "d:\\windows\\Program Files (x86)\\Microsoft Visual \ Studio\\2017\\Community", "CompilerName" -> Automatic}, {"Name" -> "Visual Studio", "Compiler" -> CCompilerDriver`VisualStudioCompiler`VisualStudioCompiler, "CompilerInstallation" -> "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\", "CompilerName" -> Automatic}} – Sjoerd C. de Vries – 2018-05-01T20:35:20.900

@SjoerdC.deVries Did you isntalled WM 11.3 after th einstalaltion of your VS2017? – Jose Enrique Calderon – 2018-05-02T00:32:42.583

@JoseECalderon Yes, I did – Sjoerd C. de Vries – 2018-05-05T22:02:18.963

@Szabolcs I wish to install Visual Studio 2015 without IDE but having trouble finding it on MS website. Could you provide a link (offline installer is preferred)? – Alexey Popkov – 2018-05-19T05:41:06.637

@AlexeyPopkov Google for "vs build tools 2015".

– Szabolcs – 2018-05-19T09:22:18.670

@Szabolcs Thank you. For some reason after completing the installation Mathematica still can't find the compiler and the environment variable VS140COMNTOOLS isn't set. What can I do to fix this? – Alexey Popkov – 2018-05-19T09:54:42.673

The documentation lists Visual Studio 2012 (!) as the latest tested version? I did install vswhere.exe using Chocolatey (Windows Package Manager) and tested it in Shell. But CCompilers[] only returns an empty list while Visual Studio is also missing from CCompilers[Full]. I never uninstalled Visual Studio Express 2015 but that is not detected now either... What to do?

– gwr – 2018-06-11T13:31:53.463

@gwr Contact support? I think you are running into an issue with 11.3 (likely the output of vswhere has some non-ASCII characters and isn't processed correctly), you will probably have to specify manually the compiler location. – ilian – 2018-06-11T13:41:45.927

Thanks, I did contact support today but felt that there may be general issues here as well (e.g. documentation update). – gwr – 2018-06-11T14:46:25.867