How to locate compiler for mex in matlab? - windows

I want to run c code from Matlab. So i started to google and saw that using mex, i can achieve it. But i got problem to run mex in matlab. Here's what i did:
1. At first i ran mex -setup in matlab command window.
2. Then i got the below response.
Please choose your compiler for building MEX-files:
Would you like mex to locate installed compilers [y]/n?
3. I wrote y and got below response
No supported SDK or compiler was found on this computer. For a list
of supported compilers, see
http://www.mathworks.com/support/compilers/R2013a/win64.html
4. I went to the link and downloaded the sdk and installed it in my windows 10. But while installing i got some problem but continued.
5. Again repeated the whole process and wrote y but got same message as above.
6. Then i tried by writing n and saw all the list of my compilers.
[1] Intel C++ 13.0 (with Microsoft Software Development Kit (SDK) linker)
[2] Intel C++ 13.0 (with Microsoft Visual C++ 2010 linker)
[3] Intel C++ 13.0 (with Microsoft Visual C++ 2012 linker)
[4] Intel C++ 12.0 (with Microsoft Software Development Kit (SDK) linker)
[5] Intel C++ 12.0 (with Microsoft Visual C++ 2008 SP1 linker)
[6] Intel C++ 12.0 (with Microsoft Visual C++ 2010 linker)
[7] Intel C++ 11.1 (with Microsoft Visual C++ 2008 SP1 linker)
[8] Intel Visual Fortran 13 (with Microsoft Software Development Kit (SDK) linker)
[9] Intel Visual Fortran 13.0 (with Microsoft Visual C++ 2010 linker)
[10] Intel Visual Fortran 13.0 (with Microsoft Visual C++ 2012 linker)
[11] Intel Visual Fortran 12 (with Microsoft Software Development Kit (SDK) linker)
[12] Intel Visual Fortran 12.0 (with Microsoft Visual C++ 2008 SP1 linker)
[13] Intel Visual Fortran 12.0 (with Microsoft Visual C++ 2008 Shell linker)
[14] Intel Visual Fortran 12.0 (with Microsoft Visual C++ 2010 linker)
[15] Intel Visual Fortran 11.1 (with Microsoft Visual C++ 2008 SP1 linker)
[16] Intel Visual Fortran 11.1 (with Microsoft Visual C++ 2008 Shell linker)
[17] Microsoft Software Development Kit (SDK) 7.1
[18] Microsoft Visual C++ 2005 SP1
[19] Microsoft Visual C++ 2008 SP1
[20] Microsoft Visual C++ 2010
[21] Microsoft Visual C++ 2012
7. The number 17 is my installed sdk. so i got a response after selecting 17.
Warning: The default location for Microsoft Software Development Kit
(SDK) compiler is:
"C:\Program Files (x86)\Microsoft Visual Studio 10.0"
but either that directory does not exist or the configuration
is invalid.
8. I have uninstalled visual studio from my computer and that directory remained
Is there any easy way to run c file from matlab or how to install compiler for mex file ??
EDIT: Now what i found is Windows Software Development Kit (SDK) for Windows 10 from this link and downloading it. I don't know that it will work or not??

I can not remember how many times that I close with striking MEX files. The following way is time-consuming but effective.
Uninstall Visual Studios and SDKs from your computer.
Find a supported version of Visual Studio from ‘https://www.mathworks.com/support/compilers.html’
Install C++ and related libraries in this Visual Studios with default directory. Do not try to choose libraries by yourself.
Run ‘mex -setup’, and let it find the compiler.
The entire process will use up a whole morning with good luck.

Related

Visual Studio 2010 x64 Compiler on Windows 10

I've installed Visual Studio 2010 Express but I need the x64 compiler toolset. I can not install the compiler toolset with the Windows 7.1 SDK on my Windows 10 machine, it says ".NET Framework 4 is not installed".
How can I get the x64 compilers of Visual Studio 2010?
For me it worked with the following steps (older Visual Studio version can be downloaded through https://www.visualstudio.com/vs/older-downloads/ (required login))
Install Microsoft Visual Studio 2010 Express (en_visual_studio_2010_vc_express_web_installer_x86_516528)
Install Microsoft Visual Studio 2010 SP1 (mu_visual_studio_2010_sp1_web_installer_x86_651694)
Install Microsoft SDK (from https://www.microsoft.com/en-us/download/details.aspx?id=8279). Note that when running the installer a warning will appear saying that "some components cannot be installed". Just ignore this (press OK) and continue with the installation using the default settings. Note that the 64-bit C++ compiler is not installed at this point.
Install KB2519277 (from https://www.microsoft.com/en-us/download/details.aspx%3Fid=4422).
Both the 32- and 64-bit Visual Studio 2010 C++ compilers should now be installed.
Note that I'm not sure if all the above steps are actually necessary and if the order is strictly relevant (e.g. it might also work without installing SP1 or installing SP1 later) but this is what worked for me.
I found an installer for VS 2010 Professional on CNet: http://download.cnet.com/Microsoft-Visual-Studio-2010-Professional/3000-2212_4-10618634.html It installed the x64 compilers as well.

Supported Windows compilers in CUDA

I am a complete novice CUDA programmer trying to get started, and I am encountering the issue mentioned here with version 5.5
"clean" error with CUDA 5.5 in Visual Studio 2010 Express
Can anyone confirm that this is an issue with version 5.5 only? Is there an earlier version that I can install e.g. 5.0, that will allow nvcc to work with the Visual Studio 10.0 Express version compiler under 64-bit Windows 7?
This is a late answer provided here to remove this question from the unanswered list.
From the NVIDIA CUDA TOOLKIT V5.0 Release Notes, Section 5.1, Table 1
Supported Windows Compilers (32-bit and 64-bit)
Compiler IDE
Visual C++ 10.0 Visual Studio 2010
Visual C++ 9.0 Visual Studio 2008
From the NVIDIA CUDA TOOLKIT V5.5 Release Notes, Table 2
Windows Compilers Supported in CUDA 5.5
Compiler IDE
Visual C++ 11.0 Visual Studio 2012
Visual C++ 11.0 Visual Studio 2012 Express (32-bit)
Visual C++ 10.0 Visual Studio 2010
Visual C++ 9.0 Visual Studio 2008
From the NVIDIA CUDA GETTING STARTED GUIDE FOR MICROSOFT WINDOWS for CUDA 6.0
Windows Compiler Support in CUDA 6.0
Compiler IDE
Visual C++ 11.0 Visual Studio 2012 Express
Visual C++ 10.0 Visual Studio 2010
Visual C++ 9.0 Visual Studio 2008
In all the above releases, there is no support for Visual Studio 2010 Express.

mex setup for Matlab

I am having some trouble with the mex setup in terms of selecting a compiler. I have attempted to install windows SDK 7.1 but it fails each time. According to THIS forum it is because i have visual studio 10.0 installed (which I do). So ideally i should be able to set up mex with this compiler. But when i try i get the following error:
Welcome to mex -setup. This utility will help you set up
a default compiler. For a list of supported compilers, see
http://www.mathworks.com/support/compilers/R2012a/win64.html
Please choose your compiler for building MEX-files:
Would you like mex to locate installed compilers [y]/n? n
Select a compiler:
[1] Intel C++ 12.0 (with Microsoft Software Development Kit (SDK) linker)
...
[14] Microsoft Visual C++ 2010
[0] None
Compiler: 14
Warning: The default location for Microsoft Visual C++ 2010 compiler is:
"C:\Program Files (x86)\Microsoft Visual Studio 10.0"
but either that directory does not exist or the configuration
is invalid.
*****************************************************************************
Error: Microsoft Visual C++ 2010 requires the Microsoft Windows Software
Development Kit (SDK), but the SDK cannot be found. Examine your
Microsoft Visual C++ 2010 installation.
*****************************************************************************
Error using mex (line 206)
Unable to complete successfully.
So obviously i do need SDK??? I have tried un-installing the SDK 7.1 from microsoft several times but no luck.
I have thought that maybe i need to manually point mex deeper into the visual studio file system in order to find the compiler, any ideas about that?
I am using Windows 7 64 bit with matlab R2012a.
Thanks for your help.
I don't know the reason for this but this is how I got it right.
Uninstall all versions of Microsoft Visual C++ Redistributable from your computer.
Install Microsoft Visual C++ 2010 Service Pack 1 Compiler Update for the Windows SDK 7.1 from here: https://www.microsoft.com/en-in/download/details.aspx?id=4422
Try mex -setup again.

ARM visual studio 2010 2012

I would like to know if there is a plugin to help develop ARM target in visual studio 2010 or 2012.
thank's
Visual Studio 2008 includes an ARM compiler and can target Windows CE/Windows Mobile.
Visual Studio 2010 does not include ARM compiler.
Visual Studio 2012 includes an ARM compiler and can target Windows RT, and probably also Windows Phone 8 (I didn't try to compile for the latter).

Setting up mex to use the Visual Studio 2010 compiler

I have Visual Studio 2010 installed. However, MATLAB doesn't find the compiler.
>> mex -setup
Please choose your compiler for building external interface (MEX) files:
Would you like mex to locate installed compilers [y]/n? y
Select a compiler:
[0] None
Compiler:
If I answer n to the question, I get the following
Would you like mex to locate installed compilers [y]/n? n
Select a compiler:
[1] Intel C++ 11.1 (with Microsoft Visual C++ 2008 SP1 linker)
[2] Intel C++ 9.1 (with Microsoft Visual C++ 2005 SP1 linker)
[3] Intel Visual Fortran 11.1 (with Microsoft Visual C++ 2008 SP1 linker)
[4] Intel Visual Fortran 11.1 (with Microsoft Visual C++ 2008 Shell linker)
[5] Intel Visual Fortran 10.1 (with Microsoft Visual C++ 2005 SP1 linker)
[6] Microsoft Visual C++ 2005 SP1
[7] Microsoft Visual C++ 2008 Express
[8] Microsoft Visual C++ 2008 SP1
[0] None
Compiler: 8
The default location for Microsoft Visual C++ 2008 SP1 compilers is C:\Program Files (x86)\Microsoft Visual Studio 9.0,
but that directory does not exist on this machine.
Use C:\Program Files (x86)\Microsoft Visual Studio 9.0 anyway [y]/n? n
Please enter the location of your compiler: [C:\Program Files (x86)\Microsoft Visual Studio 9.0]
What is the easiest way to compile my c++ code to make it available in MATLAB? Install Visual C++ 2008? oO
It depends on what MATLAB version you are using. R2010b supports VS2010 out of the box. If you have R2010a, there is a patch available:
Update From the World of MEX: Visual Studio 2010 Support
How can I use Microsoft Visual C++ 2010 to create MEX files with MATLAB 7.10 (R2010a)?
There are more than 1 ways of working around your problem, and only one involves money :)
Buy/Upgrade to a new Matlab version (R2010b recognizes and works with VS2010).
You don't have to install the full VS2008 package, the old Windows SDK v7.0 is enough. Once installed, matlab should recognize is when you do a mbuild -setup.
As you yourself suggested, install VS2008.
For future reference: http://www.mathworks.com/support/compilers/R2010b/index.html
You can also make your c++ code available to Matlab without using mex. Matlab is capable of loading external DLLs and calling their functions. So you can wrap your code into a DLL, and bypass mex entirely.
Generally, I found this to be an easier way of calling C or C++ code from matlab. The drawback is that you would not have all the facilities for manipulating matlab data structures that mex provides. You can still pass data back and forth, some things are more cumbersome, such as allocating an array in C and giving the ownership of it to matlab.

Resources