mex and the Visual Studio Community 2022 C/C++ compiler

Dear Colleagues,
I have recently installed Visual Studio Community 2022 because the C/C++ compiler is required by Quanser/QUARC. The default installation is not compatible with MATLAB mex so the
>>mex -setup
command returns an error.
After a bit of trial an error I have found that selection of the MSVC v140 - VS 2015 C++ build tools installs the 2015 version of the compiler that is compatibe with mex. Consequwntly, I can set it up mex and I am able to run the Quanser QUARC demos.Please see below the screenshot obtained from the Modify option of the VS Community 2022 installer app.
After this installation I get
>> mex -setup
MEX configured to use 'Microsoft Visual C++ 2015 (C)' for C language compilation.
I am writing to ask if anyone has a experience with the VS Community C/C++ compilers in general and if anything else is needed from this option list. I will update this thread if I find missing options.
Thank you.
BU

8 Comments

No experience here since Community Edition is never allowed at my workplace due to the licensing terms. I seem to recall mex did not support Community Edition until VS 2017. But if it works, let us know...
Thank you Benjamin. At my workplace we are so small and poor that we qualify for the VS Community Edition license. I have double checked VS 2017 with the configuration below and I get the typical mex error of not detected. So I'll revert to VS 2015.
BU
>> mex -setup
Error using mex
Supported compiler not detected. You can install the freely available MinGW-w64 C/C++ compiler; see Install
MinGW-w64 Compiler. For more options, visit https://www.mathworks.com/support/compilers.
Hi Bogdan Udrea,
Thank you so much for sharing the details. I also want to run Quanser/Quarc demo and getting the similar mex error as you were having.
I have done the modification in Visual Studio Community 2022 as per your suggestion but It didn't work for me. I am using Matlab 2021b version. Can you please let me know what Matlab version you were using?
Thanks in advance!
Muhammad Ali
HI Muhammad,
Did you resolve the error? I am in the same scenario as you. Can you please let me know the solution if you had found one?
Could you confirm that you are using R2021b ? According to https://www.mathworks.com/support/requirements/previous-releases.html the VS2015 family was not supported for anything in R2021b -- you would have needed VS 2017 or VS 2019 or MinGW or one of the Intel compilers.
Remember to use
mex -setup C++
to set up the C++ compiler -- and remember that when it says VS 2017C++ then that is the C++ compiler, not the C compiler.
Thanks for sharing @Bogdan Udrea - the little detail of which MSCV version to install to get MATLAB to recognise Visaul C++ as a compiler option saved me time today.
For me, none of these comments got it working.
In my case, I could only select the VS C++ build tools within MATLAB, after I had installed the Windows (10) SDK using the VS installer.

Sign in to comment.

Answers (0)

Categories

Products

Release

R2021b

Asked:

on 2 Mar 2022

Commented:

Ben
on 19 Aug 2025

Community Treasure Hunt

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

Start Hunting!