在vs編程中,常常涉及到32位和64位程序的編譯,怎么判斷當前編譯是32位編譯還是64位編譯?如何判斷
是debug下編譯還是release下編譯?因為之前用到,這里記錄一下,省的忘了又要瘋狂的google。
1.判斷是debug編譯還是release編譯。
如果_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 |
最后附上根據相應編譯情況,進行有條件的鏈接相應靜態庫的示例代碼,其實就是一些宏定義語句的使用:
#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;
轉自:http://blog.csdn.net/zhuyingqingfen/article/details/24352137