❶ 编译器预定义的宏(可以用来区分使用的是哪种编译器) 详细�0�3
1、_MSC_VER 是微软C/C++编译器——cl.exe 编译代码时预定义的一个宏。需 要针对cl 编写代码时, 可以使用该宏进行条件编译。 2、_MSC_VER 的值表示cl 的版本。需要针对cl 特定版本编写代码时, 也可以使用 该宏进行条件编译。 3、_MSC_VER 的类型是"int",具体版本号定义如下: MS VC++ 9.0 _MSC_VER = 1500 MS VC++ 8.0 _MSC_VER = 1400 MS VC++ 7.1 _MSC_VER = 1310 MS VC++ 7.0 _MSC_VER = 1300 MS VC++ 6.0 _MSC_VER = 1200 MS VC++ 5.0 _MSC_VER = 1100 其中MS VC++ 9.0 就是Visual C++ 2008,MS VC++ 8.0 就是Visual C++2005。 二、介绍预定义宏“__GNUC__” 1、__GNUC__ 是gcc 编译器编译代码时预定义的一个宏。需要针对gcc 编写代码时, 可以使用该宏进行条件编译。 2、__GNUC__ 的值表示gcc 的版本。需要针对gcc 特定版本编写代码时,也可以使 用该宏进行条件编译。 3、__GNUC__ 的类型是“int” 三、预定义宏"__MINGW32__" 1、MinGW编译器 四、symbian sdk 预定义宏: symbian 平台,定义"__SYMBIAN32_" 3rd MR 版及之前的那个3rd 版本,定义"__SERIES60_30__" 3rd FP1 版,定义"__SERIES60_31__" 3rd FP2 版,定义"__SERIES60_32__" 另外,还有一个"__SERIES60_3x__"。若不需区分具体是哪一个3rd 版,则用之。
❷ 如何在MATLAB R2010a 中使用Visual C++ 2010编译器
1、安装补丁VS2010MEXSupport.zip
由于MATLAB R2010a 发布的时间要比 VS2010早,所以在该版本识别不了VC++2010编译器。不过R2010a之后的版本应该不会有这种问题了。
解压补丁包,将其中的文件放到 D:Program 文件夹下。
2、在MATLAB中安装VC++ 2010 编译器
打开Matlab,在 command window 中输入 mex -setup
>> mex -setup
Please choose your compiler for building external interface (MEX) files:
Would you like mex to locate installed compilers [y]/n?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] Lcc-win32 C 2.4.1
[7] Microsoft Visual C++ 6.0
[8] Microsoft Visual C++ 2005 SP1
[9] Microsoft Visual C++ 2008 Express
[10] Microsoft Visual C++ 2008 SP1
[11] Microsoft Visual C++ 2010
[12] Microsoft Visual C++ 2010 Express
[13] Open WATCOM C++
[0] None
Compiler:12
注意,如果选择 n 之后,没有列出这么多编译器选项,甚至没有出现VC++ 2010。 不要慌,此时选择 0,即None。
Compiler: 0
mex: No compiler selected. No action taken.
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/en/data/1-5C27B9/?solution=1-5C27B9
Building with the -largeArrayDims option enables the new API.
然后在command window 里再次输入 mex -setup。
>> mex -setup
Please choose your compiler for building external interface (MEX) files:
Would you like mex to locate installed compilers [y]/n?n (一定要选择 n)
此时就会列出很多编译器,包括已经VC++2010。如果还没有,可重复几次以上过程。当然前提是必须安装VS2010,否则,再怎么重复,也找不到VC++2010编译器。
列出VC++2010编译器之后,我相信接下该怎么做对大家来说没问题。
3、error C2371: 'char16_t' : redefinition; different basic types
在混合编程中,也许会出现如下错误:
C:Microsoft Visual Studio 10.0VCINCLUDEyvals.h(576) : error C2371: 'char16_t' : redefinition; different basic types
C:.h(330) : see declaration of 'char16_t'
原因是VS2010中的yvals.h添加了char16_t的定义,而Matlab的matrix.h也包含对char16_t的定义,所以同时包含这两个头文件的话,会导致重复定义char16_t的错误。
完全没有必要修改这两个头文件(以防修改之后,会在将来导致一些问题),只需要在包含matrix.h之前包含yvals.h即可。例如:
#include<yvals.h>
#if(_MSC_VER>=1600)
#define__STDC_UTF_16__
#endif
#include"mex.h"
mex.h 包含matrix.h。这就要求我们必须知道所包含的头文件是否包含matrix.h。