在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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-16
  • 2021-10-26
猜你喜欢
  • 2022-02-16
  • 2022-01-13
  • 2021-12-22
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
  • 2021-10-24
相关资源
相似解决方案