Setting up mex to use the Visual Studio 2010 compi

2020-06-03 04:12发布

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

3条回答
走好不送
2楼-- · 2020-06-03 04:30

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:

查看更多
贼婆χ
3楼-- · 2020-06-03 04:30

There are more than 1 ways of working around your problem, and only one involves money :)

  1. Buy/Upgrade to a new Matlab version (R2010b recognizes and works with VS2010).
  2. 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.
  3. As you yourself suggested, install VS2008.

For future reference: http://www.mathworks.com/support/compilers/R2010b/index.html

查看更多
别忘想泡老子
4楼-- · 2020-06-03 04:44

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.

查看更多
登录 后发表回答