# MATLAB Spoken Here

## Update From the World of MEX: Visual Studio 2010 Support

This week I’d like to welcome back guest blogger, Ken Atwell from the MATLAB Product Management team this week to talk about our support of Visual Studio 2010.

With the recent release of Microsoft Visual Studio 2010, we were almost immediately asked, “does it work with MATLAB”? Since Visual C++ 2010 was released after MATLAB R2010a, it could not be officially supported in the shipping release. With Visual C++ 2010 now “gold” and validated, we are making available a patch to 64-bit and 32-bit MATLAB R2010a (naturally, for Windows) that allows you to build MEX files with this new version of Visual C++. The patch supports both the Professional and Express versions of Visual C++, and will work with both the Professional and Student versions of MATLAB. This patch works only with R2010a; using the patch with any version of MATLAB other than R2010a is not supported.

And, while we’re talking about compilers for Windows, we often get asked, “Where can I get a free compiler for Windows (especially 64-bit Windows)?” Visual C++ Express is free and probably your best option. If you are using Visual C++ Express with 64-bit MATLAB, you will also need to install a matching version of the Windows SDK (also free) to get the 64-bit compiler you’ll need.

All of the above is captured in our Supported and Compatible Compilers page, which should be everyone’s first-stop shop for information concerning what compilers MATLAB supports.

What compiler do you use with MATLAB, if any? Chime in below!

### 20 Responses to “Update From the World of MEX: Visual Studio 2010 Support”

1. Drazick replied on :

Could you integrate 64 bit C++ compiler into the next iteration of Matlab as you do for the 32 bit versions?

Because you don’t the integration between Photoshop CS5 and Matlab won’t work.

2. Ken Atwell (MathWorks) replied on :

Drazick, as you’ve noticed, MATLAB includes a basic compiler, lcc, on 32-bit Windows. Unfortunately, lcc is not available on 64-bit Windows, so you need to provide your own. Installing Visual C++ Express and the matching Windows SDK (both free) and should suit your needs. See http://www.mathworks.com/support/compilers/R2010a/win64.html for all options.

I am not familiar with the MATLAB integration that CS5 provides, so I cannot offer specific guidance. These threads from Adobe’s web site may be instructive and suggest that 64-bit can be made to work if both MATLAB and CS are 64-bit:

3. Dvijotham replied on :

Hi,
Thanks for the patch, I’m able to use VS 2010 for my mexing needs now. However, I’m still not able to use it to generate mex files from the Embedded MATLAB code subset. Any advice on this?

4. Björn replied on :

Hi,

I need to mex some files in 64-bit MATLAB 2010a on Windows 7. I have Microsoft Visual Studio 2010 Professional installed, and also the VS2010MEXSupport downloaded, unzipped and put into the MATLAB2010a directory. Still the mex -setup does not find Microsoft Visual C++ 2010.
What am I doing wrong?

/Björn

5. Ken Atwell (MathWorks) replied on :

As of last week, R2010b was released. It includes much richer support for Visual Studio 2010; no patch is needed. See http://www.mathworks.com/support/compilers/R2010b

@Dvijotham, the patch enables MEX compilation only. For Embedded MATLAB, you will need to move to R2010b to use Visual Studio 2010.

@Björn, sounds like you’re doing the right things. Double-check that the patch was unzipped to the right place, and if problems persist, please contact technical support.

6. shaun replied on :

To get Matlab2010a and PS extended (CS3,4,5) to work on x64, I had to install VS2008 Pro. VS2008 Express and the Windows SDK alone were not sufficient, since there is no support in express for loadlibrary (see: http://www.mathworks.com/support/compilers/R2010b/win64.html).

Everything is working great now with 2010a, CS4 and VS2008Pro.

7. divya replied on :

i have the same problem as Bjorn !!!

8. Jan Simon replied on :

Is the SP1 recommended for MSVC2010 Express together with MATLAB 2011a? While I can install the SP1 for MSVC2010, the installation of the SP1 for the WinSDK7.1 fails due to mysteriously missing prerequisites.

9. Ken Atwell (MathWorks) replied on :

@Jan,

You’ve asked a good question. There is a bug in the installer for SP1 that can corrupt the SDK installation. Microsoft has issued a fix for this problem. More details and links can be found at this MATLAB Answers topic:

I hope this fix the problem.

10. David replied on :

After installing Matlab 2010a x32 on windows 7 x64 all was well. After installing VS2010MEXSupport to enable compilation with VS2010pro, matlab failed to start with the error “Windows cannot find C:\Program Files (x86)\MATLAB\R2010a Student\bin\win64\vcredist_x64.exe.” Placing the required file in that directory didn’t seem to help.

WORKAROUND:
Change all matlab 2010a shortcuts from
“C:\Program Files (x86)\MATLAB\R2010a Student\bin\matlab.exe”

TO
“C:\Program Files (x86)\MATLAB\R2010a Student\bin\win32\MATLAB.exe”

use this executable, and all is well.

Thanks for the patch information.

11. dominique replied on :

Hi, thanks a lot,
This took me a all day looking for !

12. dominique replied on :

I just see something horrible !!!! : this patch does not work with dlls !!!!! only Mex file !

pfffffffffff

13. Saima replied on :

Thanx a lot for the patch and the matlab shortcut path correction ! :)

14. Duc Pham replied on :

Hi,
I am using Matlab 2010b. I also installed Microsoft Window SDK7.1. When I use command: mex -setup. Matlab could not find the new compiler. I found only lcc-win32 v2.4.1. Is there a way for Matlab to automatically find the new compiler? If not, what should I do so that Matlab can find the new compiler? Thanks.

15. Aurélien replied on :

Try with SDK 6.1 which is supported :
http://www.mathworks.com/support/compilers/R2010b/

Microsoft Visual C++ 2008 Express Edition and Windows SDK 6.1 1
Available at no charge

16. Sridutt replied on :

Hi, I had a PC with R009b & MSVStudio2008. There were no compatibility issues. Now my new PC has R2009b and MSVC++ Express 2010. There are problems getting the same codes work with.
1. The MSVStud doesn’t show upin mex -setup.

What is the way to go around with R2009b is fixed?
Also is mex from one machine reusable in other? Like exe’s as I am not finding them to be so.

17. Aurélien replied on :

Hi Sridutt

MSVC++ Express 2010 is not supported in 9b : it is the reason why mex-setup doesn’t display it. See suported compilers for 9b here :
http://www.mathworks.com/support/compilers/R2009b/

However inR2011a it is supported:
http://www.mathworks.com/support/compilers/R2011a/win32.html

Aurélien

18. Sridutt replied on :

Thanks Aurélien,

I’ve 1 more Question. Are mex executables reusable with other PC’s (Same Matlab version)?

19. Aurélien replied on :

Yes the most important thing is mex-files can only be run under the same Operating System.
Your mex file is platform dependent , a windows mex-file (mexw32/mexw64 extension) will not work under Linux or Mac for example.

20. Andreas replied on :

Hello

I want to ask if there is a patch for using Matlab R2008a and MVS2010 too. My intend is to compile C-Code with mex from Matlab and to debug the application (sfunction integrated in simulink) by attaching to the matlab process from visual studio.

Andreas

 Name (required) E-mail (required, will not be published) Website (optional) Spam protection (required): What is 1 + 9 ?

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>


If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).

News from the intersection of MATLAB, Community, and the web.

These postings are the author's and don't necessarily represent the opinions of MathWorks.