MATLAB how to change default compiler? - c++

I am working with MATLAB R2015b and trying to use MEX files. When I type the commad line "mex - setup", MATLAB returns me "MEX configured to use 'Microsoft Windows SDK 7.1(C)' for C language compilation". However, to change this default compiler to work with Microsoft Visual Studio Community.
How can I change the default compiler of MATLAB?

mex -setup lets you choose the compiler over the installed supported compilers you have.
Obviously the compiler needs to be installed , and needs to be one of the following : https://uk.mathworks.com/support/compilers/R2015b/index.html .
"Microsoft Visual Studio Community" does not appear to be on the list.

Related

Matlab does not see C++ compiler

I've recently installed Matlab R2016a.
When I try to execute
mex -setup
I've got the following message:
Error using mex
No supported compiler or SDK was found. You can install the freely available MinGW-w64 C/C++ compiler; see Install MinGW-w64 Compiler. For
more options, visit http://www.mathworks.com/support/compilers/R2016a/win64.html
I did check the list and it turned out that I do have all tools in my system that are compatible with this Matlab version. I also installed Windows SDK for Windows 10.
Doest anyone know what might be the problem here?
After a while, I realised that Microsoft Visual Studio does not install C++ compiler through a express setup, which makes a lot of sense... I guess.

matlab mex cannot find vcomp.lib when openmp is used

I am trying to mex a c++ source file containing openmp usages. In the mex command, i have added COMPFLAGS="/openmp $COMPFLAGS" but it says cannot find vcomp.lib. My matlab mex have been setup to use the compiler of Windows SDK 7.1 located in C:\Program Files. I checked the lib files inside this SDK and didn't find vcomp.lib. Anyone knows how can I install openmp to Windows SDK 7.1? Thanks a lot!
Based on this thread, it seems openmp is not shipped with Windows SDK. It is only shipped with Visual Studion Professional or Ultimate.
This matlab central site proposed a method to enable the matlab mex to use the Visual Studio 2013 compiler instead of the Windows SDK compiler. OpenMP is shipped with Visual Studio 2013 Professional and I can now compile code with OpenMp Enabled!

MATLAB R2013b does not support Visual Studio 2013?

I have recently installed VS 2013. I have a .cpp project which I want to compile into mex with MATLAB 2013b. As soon as I enter:
mex -setup
in MATLAB and then I select "y" for "Would you like mex to locate installed compilers?", I receive the message that: "No supported SDK or compiler was found on this computer."
How can I get around this problem?
Visual Studio 2013 is not supported by MATLAB R2013b. See this link for more details: http://www.mathworks.com/support/compilers/R2013b/. The latest compiler and environment that R2013b can support for Windows is Visual Studio 2012. Your options are to either downgrade your version of Visual Studio to one that is compatible on that list I referred you to, or upgrade your version of MATLAB to at least R2014a or higher.

How can I compile the vlfeat and mexopencv libraries in MATLAB using the Visual c++ compiler?

I am working on a computer vision project, and I need to use the vlfeat and mexopencv libraries,
I am working with MATLAB R2008a and I cannot change the MATLAB compiler to compile and setup the libraries.
I have installed Microsoft Visual C++ Express, but I don't know how to compile the libraries using the Visual C++ compiler in MATLAB.
The reason why you can't find the compiler is because you are using MATLAB R2008a. The C++ compiler you have downloaded is probably too new for MATLAB to use. My guess is that you are using Express 2013. See the following link on what compilers R2008a can support for MEX here:
http://www.mathworks.com/support/compilers/release2008a/
Specifically, for the Express edition of the Visual C++ compiler, it can only support up to Version 8.0. You are most likely using an Express edition that is newer than 8.0. As such, the only way for you to use the Visual C++ compiler with R2008a is if you download the 8.0 Express edition and install it.
You can find that compiler here: http://go.microsoft.com/fwlink/?LinkId=51410&clcid=0x409
Once you install the Visual C++ compiler, you also need to install the SDK. You can find that here:
http://www.microsoft.com/en-ca/download/details.aspx?id=6510
After you do this, you need to define the MSSdk environment variable. To do this,
go to Control Panel -> System then Advanced and Environment Variables. After, create a new variable with the name MSSdk and the value being the path of where you installed the SDK. For example: C:\Program Files\Microsoft Platform SDK for Windows Server 2003.
Good luck!

Using Visual Studio 2013's C compiler for MATLAB

I added Visual Studio 2013 as the default C compiler for MATLAB using the mex -setup command. I added Visual Studio 2013 using a download I found on the internet with the following instructions.
The files
* msvc120engmatopts.bat
* msvc120opts.bat
* msvc120opts.stp
should be copied to C:\Program Files\MATLAB\R2013a\bin\win64\mexopts .
The files
* msvc120compp.bat
* msvc120compp.stp
should be copied to C:\Program Files\MATLAB\R2013a\bin\win64\mbuildopts .
My version of MATLAB is R2011b, so I replaced the path appropriately.
Here's me using it to run a C function to verify if the compiler has been linked.
Log File
I found out about this method from this answer.
However, when I use a MATLAB function within a Simulink Model, I get the following error message just like I did before I linked the VS2013 compiler to MATLAB.
Unable to locate a C-compiler required by Stateflow and MATLAB Function blocks.
Use 'mex -setup' to select a supported C-compiler.
Okay, so the only thing that works for my version of MATLAB "R2011b" is Microsoft SDK 7.1 since the other compilers are too old for Windows 7 64 bit. MinGW-64 bit is unsupported. Although it works on MATLAB it is not recognized by Stateflow.
So I just downloaded the .iso file from here.
If you face any difficulty while installing the SDK, then try this.