如果_DEBUG定義了表示是debug編譯,否則是release編譯。
2.判斷是32位編譯還是64位編譯。
在 Win32 配置下,_WIN32 有定義,_WIN64 沒有定義。在 x64 配置下,兩者都有定義。即在 VC 下,_WIN32 壹定有定義。
因此,WIN32/_WIN32 可以用來判斷是否 Windows 系統(對於跨平臺程序),而 _WIN64 用來判斷編譯環境是 x86 還是 x64。附壹個表:
常量\定義 預定義選項 Windows.h VC編譯器
WIN32 Win32 √(minwindef.h) ×
_WIN32 × × √
_WIN64 × × x64
最後附上根據相應編譯情況,進行有條件的鏈接相應靜態庫的示例代碼,其實就是壹些宏定義語句的使用:
[cpp] view plaincopy在CODE上查看代碼片派生到我的代碼片
#include "json/json.h"
#ifdef _DEBUG
#ifndef _WIN64
#pragma comment(lib,"json/json_mtd.lib")
#else
#pragma comment(lib,"json/json_mtd_x64.lib")
#endif
#else
#ifndef _WIN64
#pragma comment(lib,"json/json_mt.lib")
#else
#pragma comment(lib,"json/json_mt_x64.lib")
#endif
#endif
using namespace Json;