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
}
相关推荐
噜噜大王_2 小时前
深入理解 C 语言内存操作函数:memcpy、memmove、memset、memcmp
c语言·开发语言
嵌入式×边缘AI:打怪升级日志2 小时前
Qt GUI 程序开发完全学习笔记(从环境搭建到第一个界面程序
qt
paeamecium2 小时前
【PAT甲级真题】- Cars on Campus (30)
数据结构·c++·算法·pat考试·pat
UrSpecial3 小时前
从零实现C++轻量线程池
c++·线程池
chh5633 小时前
C++--模版初阶
c语言·开发语言·c++·学习·算法
会编程的土豆4 小时前
01背包与完全背包详解
开发语言·数据结构·c++·算法
hetao17338375 小时前
2026-04-12~14 hetao1733837 的刷题记录
c++·算法
jinyishu_6 小时前
几道链表经典算法题
c语言·数据结构·算法·链表
智者知已应修善业6 小时前
【51单片机4位数循环小数位移数值位移】2023-6-9
c++·经验分享·笔记·算法·51单片机
王璐WL6 小时前
【C++】string,vector和list对比
c++·list