Matlab 2009b win7 64bits编译cpp文件问题

在使用一些matlab程序的时候,总有人喜欢部分代码使用C写,那么我们在运行的时候需要进行编译。

Error: Could not detect a compiler on local system which can compile the specified input file(s) Error using mex

此时,我们需要在matlab命令窗输入:

mex -setup

进行安装,但是遇到了问题:

>> 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: 1
Please select from 0-0
Compiler:

可以看到,没有可选的编译器。。。。。。

后来发现应该选择n,如下:
>> mex -setup
Please choose your compiler for building external interface (MEX) files:

Would you like mex to locate installed compilers [y]/n? n

Select a compiler:
[1] Intel C++ 9.1 (with Microsoft Visual C++ 2005 SP1 linker)
[2] Intel Visual Fortran 10.1 (with Microsoft Visual C++ 2005 SP1 linker)
[3] Microsoft Visual C++ 2005 SP1
[4] Microsoft Visual C++ 2008 Express
[5] Microsoft Visual C++ 2008 SP1

[0] None

Compiler: 3

The default location for Microsoft Visual C++ 2005 SP1 compilers is C:\Program Files (x86)\Microsoft Visual Studio 8,
but that directory does not exist on this machine.

Use C:\Program Files (x86)\Microsoft Visual Studio 8 anyway [y]/n? n
Please enter the location of your compiler: [C:\Program Files (x86)\Microsoft Visual Studio 8] C:\Program Files (x86)\Microsoft Visual Studio 8

Please verify your choices:

Compiler: Microsoft Visual C++ 2005 SP1
Location: C:\Program Files (x86)\Microsoft Visual Studio 8

Are these correct [y]/n? y

*****************************************************************************
Error: Could not find the 64-bit compiler. This may indicate that the
“X64 Compilers and Tools” is not installed. To build 64-bit
MEX-files Microsoft Visual C++ 2005 requires that these tools are
installed properly.
*****************************************************************************

Trying to update options file: C:\Users\jacoxu\AppData\Roaming\MathWorks\MATLAB\R2009b\mexopts.bat
From template: D:\PROGRA~1\MATLAB\R2009b\bin\win64\mexopts\msvc80opts.bat

Done . . .

**************************************************************************
Warning: The MATLAB C and Fortran API has changed to support MATLAB
variables with more than 2^32-1 elements. In the near future
you will be required to update your code to utilize the new
API. You can find more information about this at:

http://www.mathworks.com/support/solutions/data/1-5C27B9.html?solution=1-5C27B9

Building with the -largeArrayDims option enables the new API.
**************************************************************************

=====但是编译,仍然存在问题。。。

>> mex cimgnbmap.cpp
Error: Could not find the compiler “cl” on the DOS path.
Use mex -setup to configure your environment properly.

D:\PROGRA~1\MATLAB\R2009B\BIN\MEX.PL: Error: Unable to locate compiler.

??? Error using ==> mex at 221
Unable to complete successfully.

>>

然后返回到这里的建议:

http://www.mathworks.com/support/compilers/R2009b/win64.html

具体的解决方案可以看这里:

http://www.mathworks.com/matlabcentral/answers/98351-how-can-i-set-up-microsoft-visual-studio-2008-express-edition-for-use-with-matlab-7-7-r2008b-on-64

貌似在VC安装的时候要手动选择64位,默认的是32位的。

排查问题的过程中,感觉大部分问题都是集中在C编译器x64还是x32的选择上,而且越新的matlab版本问题越少,matlab 2009b之前的版本问题比较多。很多人问为什么window下的问题比较多,可能还是因为x64或x32的问题,而linux大多为服务器,统一64位,便问题比较少。

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>