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
}
相关推荐
樱木Plus4 小时前
深拷贝(Deep Copy)和浅拷贝(Shallow Copy)
c++
RuoZoe2 天前
重塑WPF辉煌?基于DirectX 12的现代.NET UI框架Jalium
c语言
blasit2 天前
笔记:Qt C++建立子线程做一个socket TCP常连接通信
c++·qt·tcp/ip
肆忆_3 天前
# 用 5 个问题学懂 C++ 虚函数(入门级)
c++
不想写代码的星星3 天前
虚函数表:C++ 多态背后的那个男人
c++
端平入洛5 天前
delete又未完全delete
c++
祈安_5 天前
C语言内存函数
c语言·后端
端平入洛6 天前
auto有时不auto
c++
norlan_jame7 天前
C-PHY与D-PHY差异
c语言·开发语言
哇哈哈20217 天前
信号量和信号
linux·c++