您的位置:首页 > 其它

如何确定VS编译器版本--_MSC_VER

2013-12-09 10:50 375 查看
如何确定VS编译器版本

_MSC_VER是MSVC编译器的内置宏,定义了编译器的版本,_MSC_VER 值对应版本关系

MSVC++ 11.0 _MSC_VER = 1700 (Visual Studio 2012)

MSVC++ 10.0 _MSC_VER = 1600 (Visual Studio 2010)

MSVC++ 9.0 _MSC_VER = 1500 (Visual Studio 2008)

MSVC++ 8.0 _MSC_VER = 1400 (Visual Studio 2005)

MSVC++ 7.1 _MSC_VER = 1310 (Visual Studio 2003)

MSVC++ 7.0 _MSC_VER = 1300 (Visual Studio 2002)

MSVC++ 6.0 _MSC_VER = 1200

MSVC++ 5.0 _MSC_VER = 1100

example:

#if (_MSC_VER == 1300) //vc7

#import "acax16ENU.tlb" no_implementation raw_interfaces_only named_guids

#elif (_MSC_VER == 1200) //vc6

#import "acad.tlb" no_implementation raw_interfaces_only named_guids

#elif (_MSC_VER == 1400) //vc8

#import "acax17ENU.tlb" no_implementation raw_interfaces_only named_guids

#elif (_MSC_VER == 1500) //vc9

#import "acax18ENU.tlb" no_implementation raw_interfaces_only named_guids

#endif

在程序中加入_MSC_VER宏可以根据编译器版本让编译器选择性地编译一段程序。例如一个版本编译器产生的lib文件可能不能被另一个版

本的编译器调用,那么在开发应用程序的时候,在该程序的lib调用库中放入多个版本编译器产生的lib文件。在程序中加入_MSC_VER宏

,编译器就能够在调用的时根据其版本自动选择可以链接的lib库版本,如下所示。

#if _MSC_VER >= 1400 // for vc8, or vc9

#ifdef _DEBUG

#pragma comment( lib, "SomeLib-vc8-d.lib" )

#else if

#pragma comment( lib, "SomeLib-vc8-r.lib" )

#endif

#else if _MSC_VER >= 1310 // for vc71

#ifdef _DEBUG

#pragma comment( lib, "SomeLib-vc71-d.lib" )

#else if

#pragma comment( lib, "SomeLib-vc71-r.lib" )

#endif

#else if _MSC_VER >=1200 // for vc6

#ifdef _DEBUG

#pragma comment( lib, "SomeLib-vc6-d.lib" )

#else if

#pragma comment( lib, "SomeLib-vc6-r.lib" )

#endif

#endif
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: