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.
Related
I am trying to debug a Fortran code. I have installed Intel Parallel Studio XE which includes the iFort compiler and Microsoft Visual Studio. During the installation of Intel Parallel Studio XE, it showed a message saying it's now integrated with Visual Studio 2019 but when I try to create a new project in Visual Studio, it does not show an option for Intel Fortran Compiler, so I cannot create a Fortran project.
Any ideas on how to use the Intel Fortran compiler with Visual Studio?
Thanks!
I found the solution... posting here so that it can help others who might stumble upon the same problem. You need to install the Desktop development with C++ workload in Visual Studio. Refer to the links below:
https://software.intel.com/en-us/forums/intel-fortran-compiler/topic/843126
https://software.intel.com/en-us/articles/intel-parallel-studio-xe-compilers-required-microsoft-visual-studio
Visual Studio 2015 Update 2 has been released for 7 days. Where can I download the Visual C++ Update 2 runtime so I can run the applications compiled with Visual C++ 2015 Update 2?
Here is the download
Microsoft Visual C++ 2015 Redistributable installs run-time components
of Visual C++ libraries. These components are required to run C++
applications that are developed using Visual Studio 2015 Update 3 and
link dynamically to Visual C++ libraries. The packages can be used to
run such applications on a computer even if it does not have Visual
Studio 2015 installed. These packages also install run-time components
of C Runtime (CRT), Standard C++, MFC, C++ AMP, and OpenMP libraries.
Microsoft Visual C++ 2015 Redistributable includes bug fixes to the
runtime DLLs and also the latest versions for KB 2999226.
There are two files in the Visual Studio 2015 Update 2 VC++ Redistributable package.
vc_redist.x64.exe (v14.0.23918.0).
https://download.microsoft.com/download/0/5/0/0504B211-6090-48B1-8DEE-3FF879C29968/vc_redist.x64.exe
vc_redist.x86.exe (v14.0.23918.0).
https://download.microsoft.com/download/0/5/0/0504B211-6090-48B1-8DEE-3FF879C29968/vc_redist.x86.exe
For those that care, the x64 version sets the following registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\DevDiv\VC\Servicing\14.0\RuntimeMinimum\UpdateVersion (REG_SZ) to the value "14.0.23918".
For the x86 version, check for the existence of the registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall{2e085fd2-a3e4-4b39-8e10-6b8d35f55244} If it exists, the update is already installed.
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.
I install visual studio 2013 ultimate on a x64, and i get with is components from 2005 and a whole bunch for x86 ?!
Microsoft Visual C++ 2005 redistributable x86
It also , if i am not mistaken, gives me a version of visual studio 2010 as well as tooling and files only associated for those versions. There was no option to negate this. Do i really need all of this?
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.