_MSC_VER详细介绍 _MSC_VER详细介绍

_MSC_VER详细介绍

转自:http://www.cnblogs.com/braver/articles/2064817.htmlhtml

_MSC_VER是微软的预编译控制。post

_MSC_VER能够分解为:url

MS:Microsoft的简写。spa

C:MSC就是Microsoft的C编译器。code

VER:Version的简写。htm

_MSC_VER的意思就是:Microsoft的C编译器的版本。blog

微软不一样时期,编译器有不一样的版本:开发

MS VC++10.0 _MSC_VER=1600get

MS VC++9.0 _MSC_VER=1500编译器

MS VC++8.0 _MSC_VER=1400

......

其中MS VC++10.0就是Visual C++ 2010,MS VC++9.0就是Visual C++2008,MS VC++8.0就是Visual C++2005

在程序中加入_MSC_VER宏能够根据编译器版本让不一样版本的编译器选择性地编译一段程序。

查看编译的版本信息,能够在Command line里敲 cl /?

 

文章二

_MSC_VER定义编译器的版本。常见编译器版本_MSC_VER值:

MSVC++ 11.0 _MSC_VER = 1700 (Visual Studio 2011) 
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 
MSVC++ 6.0  _MSC_VER = 1200 
MSVC++ 5.0  _MSC_VER = 1100

 

在程序中加入_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