Qt的pro文件里如何判断系统是32位或64位

本文介绍了四种不同的方法来检测Qt项目的编译目标架构(32位或64位)。这些方法包括使用QT_ARCH宏、QMAKE_TARGET.arch属性、自定义配置参数以及设置TARGET_ARCH变量。每种方法都有其适用场景,如跨平台兼容性或特定于Windows的需求。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转载自:http://shitou7630.blog.163.com/blog/static/3269953620161126105156562/

1、解决方案1

Since Qt5 you can use QT_ARCH  to detect whether your configuration is 32 or 64. When the target is 32-bit, that returns i386  and in case of a 64-bit target it has the value of x86_64. So it can be used like:
    contains(QT_ARCH, i386) {
        message("32-bit")
    } else {
        message("64-bit")
    }

2、解决方案2

貌似也有人用QMAKE_TARGET.arch进行判断,但是可能只适用windows,不适合跨平台。
win32 {
    ## Windows common build here
    !contains(QMAKE_HOST.arch, x86_64) {
        message("x86 build")
        ## Windows x86 (32bit) specific build here
    } else {
        message("x86_64 build")
        ## Windows x64 (64bit) specific build here
    }
}

3、解决方案3
利用自定义的字符变量进行判断。

Qt allows you to pass arbitrary config parameters which you can use to separate the targets.

By having a conditional config in your project file:
CONFIG(myX64, myX64|myX32) {
    LIBPATH += C:\Coding\MSSDK60A\Lib\x64
} else {
    LIBPATH += C:\Coding\MSSDK60A\Lib
}

and passing that custom config to qmake with
qmake CONFIG+=myX64
you get the wanted result.

4、解决方案4

The following code works on Windows (at least with all the recent MSVC compilers - didn't test MinGW), Mac OS X (clang) and Linux (GCC). Feel free to omit the first clause and refer to QT_ARCH  directly if you don't need Qt 4 support.

#Firstly,Set TARGET_ARCH variable.
greaterThan(QT_MAJOR_VERSION, 4) { TARGET_ARCH=$${QT_ARCH} } else { TARGET_ARCH=$${QMAKE_HOST.arch} } #Secondly, use TARGET_ARCH to check. contains(TARGET_ARCH, x86_64) { ARCHITECTURE = x64 } else { ARCHITECTURE = x86 }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值