宏定义: 各个平台+编译器

关于VS中区分debug与release,32位与64位编译的宏定义

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

ifdef _DEBUG
    #ifndef _WIN64
        #pragma comment(lib,"json/json_mtd_x86.lib")
    #else
        #pragma comment(lib,"json/json_mtd_x64.lib")
    #endif

#else
    #ifndef _WIN64
        #pragma comment(lib,"json/json_mt_x86.lib")
    #else
        #pragma comment(lib,"json/json_mt_x64.lib")
    #endif
#endif

https://blog.csdn.net/zhuyingqingfen/article/details/24352137

编译选项

    _MSC_FULL_VER//编译器所有的版本信息

    MSVC++ 14.0:  _MSC_VER = 1900  (Visual Studio 2015)
    MSVC++ 12.0:  _MSC_VER = 1800  (Visual Studio 2013)
    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
/* Test for GCC > 3.2.0 */
#if __GNUC__ > 3 || \
    (__GNUC__ == 3 && (__GNUC_MINOR__ > 2 || \
                       (__GNUC_MINOR__ == 2 && \
                        __GNUC_PATCHLEVEL__ > 0))

Another approach is to use the predefined macros to calculate a single number, then compare that against a threshold:

#define GCC_VERSION (__GNUC__ * 10000 \
                     + __GNUC_MINOR__ * 100 \
                     + __GNUC_PATCHLEVEL__)
...
/* Test for GCC > 3.2.0 */
#if GCC_VERSION > 30200

操作系统判定:
Windows : WIN32 _WIN64

Linux : linux

Solaris : __sun

编译器判定:
VC : _MSC_VER

GCC / G++ : __GNUC__

SunCC : __SUNPRO_C和__SUNPRO_CC

llvm:  __llvm__



#ifdef WIN32
//#include <WinBase.h>// 	WinBase.h(include Windows.h)  GetLastError()
#endif

#ifdef linux//记得要是小写
#endif

#ifdef MACX
#endif
//MACX - Mac OS X
//MAC9 - Mac OS 9

从qglobal.h中可以得到的信息-我们应该多研究优秀软件的源码

  MACX   - Mac OS X 
     MAC9   - Mac OS 9 
     MSDOS  - MS-DOS and Windows 
     OS2    - OS/2 
     OS2EMX - XFree86 on OS/2 (not PM) 
     WIN32  - Win32 (Windows 95/98/ME and Windows NT/2000/XP) 
     CYGWIN - Cygwin 
     SOLARIS    - Sun Solaris 
     HPUX   - HP-UX 
     ULTRIX - DEC Ultrix 
     LINUX  - Linux 
     FREEBSD    - FreeBSD 
     NETBSD - NetBSD 
     OPENBSD    - OpenBSD 
     BSDI   - BSD/OS 
     IRIX   - SGI Irix 
     OSF    - HP Tru64 UNIX 
     SCO    - SCO OpenServer 5 
     UNIXWARE   - UnixWare 7, Open UNIX 8 
     AIX    - AIX 
     HURD   - GNU Hurd 
     DGUX   - DG/UX 
     RELIANT    - Reliant UNIX 
     DYNIX  - DYNIX/ptx 
     QNX    - QNX 
     QNX6   - QNX RTP 6.1 
     LYNX   - LynxOS 
     BSD4   - Any BSD 4.4 system 
     UNIX   - Any UNIX BSD/SYSV system 

c/c++ 宏
http://os.chinaunix.net/a2008/1216/989/000000989777.shtml


详见Qt的qglobal.h

/*
   The operating system, must be one of: (Q_OS_x)
     DARWIN   - Darwin OS (synonym for Q_OS_MAC)
     SYMBIAN  - Symbian
     MSDOS    - MS-DOS and Windows
     OS2      - OS/2
     OS2EMX   - XFree86 on OS/2 (not PM)
     WIN32    - Win32 (Windows 2000/XP/Vista/7 and Windows Server 2003/2008)
     WINCE    - WinCE (Windows CE 5.0)
     CYGWIN   - Cygwin
     SOLARIS  - Sun Solaris
     HPUX     - HP-UX
     ULTRIX   - DEC Ultrix
     LINUX    - Linux
     FREEBSD  - FreeBSD
     NETBSD   - NetBSD
     OPENBSD  - OpenBSD
     BSDI     - BSD/OS
     IRIX     - SGI Irix
     OSF      - HP Tru64 UNIX
     SCO      - SCO OpenServer 5
     UNIXWARE - UnixWare 7, Open UNIX 8
     AIX      - AIX
     HURD     - GNU Hurd
     DGUX     - DG/UX
     RELIANT  - Reliant UNIX
     DYNIX    - DYNIX/ptx
     QNX      - QNX
     LYNX     - LynxOS
     BSD4     - Any BSD 4.4 system
     UNIX     - Any UNIX BSD/SYSV system
*/
 
#if defined(__APPLE__) && (defined(__GNUC__) || defined(__xlC__) || defined(__xlc__))
#  define Q_OS_DARWIN
#  define Q_OS_BSD4
#  ifdef __LP64__
#    define Q_OS_DARWIN64
#  else
#    define Q_OS_DARWIN32
#  endif
#elif defined(__SYMBIAN32__) || defined(SYMBIAN)
#  define Q_OS_SYMBIAN
#  define Q_NO_POSIX_SIGNALS
#  define QT_NO_GETIFADDRS
#elif defined(__CYGWIN__)
#  define Q_OS_CYGWIN
#elif defined(MSDOS) || defined(_MSDOS)
#  define Q_OS_MSDOS
#elif defined(__OS2__)
#  if defined(__EMX__)
#    define Q_OS_OS2EMX
#  else
#    define Q_OS_OS2
#  endif
#elif !defined(SAG_COM) && (defined(WIN64) || defined(_WIN64) || defined(__WIN64__))
#  define Q_OS_WIN32
#  define Q_OS_WIN64
#elif !defined(SAG_COM) && (defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__))
#  if defined(WINCE) || defined(_WIN32_WCE)
#    define Q_OS_WINCE
#  else
#    define Q_OS_WIN32
#  endif
#elif defined(__MWERKS__) && defined(__INTEL__)
#  define Q_OS_WIN32
#elif defined(__sun) || defined(sun)
#  define Q_OS_SOLARIS
#elif defined(hpux) || defined(__hpux)
#  define Q_OS_HPUX
#elif defined(__ultrix) || defined(ultrix)
#  define Q_OS_ULTRIX
#elif defined(sinix)
#  define Q_OS_RELIANT
#elif defined(__native_client__)
#  define Q_OS_NACL
#elif defined(__linux__) || defined(__linux)
#  define Q_OS_LINUX
#elif defined(__FreeBSD__) || defined(__DragonFly__)
#  define Q_OS_FREEBSD
#  define Q_OS_BSD4
#elif defined(__NetBSD__)
#  define Q_OS_NETBSD
#  define Q_OS_BSD4
#elif defined(__OpenBSD__)
#  define Q_OS_OPENBSD
#  define Q_OS_BSD4
#elif defined(__bsdi__)
#  define Q_OS_BSDI
#  define Q_OS_BSD4
#elif defined(__sgi)
#  define Q_OS_IRIX
#elif defined(__osf__)
#  define Q_OS_OSF
#elif defined(_AIX)
#  define Q_OS_AIX
#elif defined(__Lynx__)
#  define Q_OS_LYNX
#elif defined(__GNU__)
#  define Q_OS_HURD
#elif defined(__DGUX__)
#  define Q_OS_DGUX
#elif defined(__QNXNTO__)
#  define Q_OS_QNX
#elif defined(_SEQUENT_)
#  define Q_OS_DYNIX
#elif defined(_SCO_DS) /* SCO OpenServer 5 + GCC */
#  define Q_OS_SCO
#elif defined(__USLC__) /* all SCO platforms + UDK or OUDK */
#  define Q_OS_UNIXWARE
#elif defined(__svr4__) && defined(i386) /* Open UNIX 8 + GCC */
#  define Q_OS_UNIXWARE
#elif defined(__INTEGRITY)
#  define Q_OS_INTEGRITY
#elif defined(VXWORKS) /* there is no "real" VxWorks define - this has to be set in the mkspec! */
#  define Q_OS_VXWORKS
#elif defined(__MAKEDEPEND__)
#else
#  error "Qt has not been ported to this OS - talk to qt-bugs@trolltech.com"
#endif
 
#if defined(Q_OS_WIN32) || defined(Q_OS_WIN64) || defined(Q_OS_WINCE)
#  define Q_OS_WIN
#endif
 
#if defined(Q_OS_DARWIN)
#  define Q_OS_MAC /* Q_OS_MAC is mostly for compatibility, but also more clear */
#  define Q_OS_MACX /* Q_OS_MACX is only for compatibility.*/
#  if defined(Q_OS_DARWIN64)
#     define Q_OS_MAC64
#  elif defined(Q_OS_DARWIN32)
#     define Q_OS_MAC32
#  endif
#endif


https://blog.csdn.net/ixiaochouyu/article/details/47294041

posted @ 2015-12-01 15:11  scott_h  阅读(2379)  评论(0编辑  收藏  举报