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

转载自: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 }

猜你喜欢

转载自blog.csdn.net/lc250123/article/details/80436833
今日推荐