QT、c/c++通过宏自动判断平台

QT、c/c++通过宏自动判断平台

  • [Chapter1 QT、c/c++通过宏自动判断平台](#Chapter1 QT、c/c++通过宏自动判断平台)

Chapter1 QT、c/c++通过宏自动判断平台

原文链接:https://blog.csdn.net/qq_32348883/article/details/123063830

背景

为了更好的进行跨平台移植、编译、调试。

具体操作

宏操作

cpp 复制代码
#ifdef _WIN32
   //define something for Windows (32-bit and 64-bit, this part is common)
   #ifdef _WIN64
      //define something for Windows (64-bit only)
   #else
      //define something for Windows (32-bit only)
   #endif
#elif __ANDROID__
    // do android something
#elif __linux__
    // do linux something
#elif __unix__ // all unices not caught above
    // do Unix something
#elif defined(_POSIX_VERSION)
    // do POSIX something
#else
   #error "Unknown compiler"
#endif

or 代码内操作

注意: 条件没有使能的编译内容,编译器不会对该内容进行错误检查。

cpp 复制代码
#if defined(_WIN32)
    std::cout << "this is win32 compiler" << endl;
#elif defined(_WIN64)
    std::cout << "this is win64 compiler" << endl;
#elif defined(__linux__)
    std::cout << "this is linux compiler" << endl;
#elif defined(__unix__)
    std::cout << "this is unix compiler" << endl;
#elif defined(__ANDROID__)
    std::cout << "this is android compiler" << endl;
#endif

附注QT .pro自动判断平台

QT 工程.pro内的宏自定义判断平台

bash 复制代码
unix {  
    TARGET = appname
}
macx {
    TARGET = appname2
}
win32 {
    TARGET = appname3
}
相关推荐
zmzb010313 分钟前
C++课后习题训练记录Day39
数据结构·c++·算法
qq_3106585123 分钟前
mediasoup源码走读(二)环境搭建与 Demo 运行
服务器·c++·音视频
XiaoCCCcCCccCcccC2 小时前
多路复用 select -- select 的介绍,select 的优缺点,select 版本的 TCP 回显服务器
服务器·c++
XiaoCCCcCCccCcccC2 小时前
多路复用 poll -- poll 的介绍,poll 的优缺点,poll 版本的 TCP 回显服务器
服务器·网络·c++
奔跑吧邓邓子2 小时前
【C语言实战(72)】C语言文件系统实战:解锁目录与磁盘IO的奥秘
c语言·文件系统·目录·开发实战·磁盘io
小π军3 小时前
STL利器:upper_bound与lower_bound的使用
c++
Zx623653 小时前
13.泛型编程 STL技术
java·开发语言·c++
The Last.H3 小时前
Educational Codeforces Round 185 (Rated for Div. 2)A-C
c语言·c++·算法
caron43 小时前
C++ 推箱子游戏
开发语言·c++·游戏