Qt Creator: how to tell win32 from win64

我的未来我决定 提交于 2019-12-08 05:33:29

问题


I have to do something like this in a .pro file:

win32 {
    LIBS += -L../3rdparty/libusb-win32/lib/msvc -llibusb
} else
win64 {
    LIBS += -L../3rdparty/libusb-win32/lib/msvc_x64 -llibusb
}

The problem is it doesn't work, it always links win32 library. Any suggestions?


回答1:


You can use QT_ARCH variable to detect whether your configuration is 32 or 64 :

contains(QT_ARCH, i386) {
    message("32-bit")
}else {
    message("64-bit")
}

When the target is 32-bit, the variable returns i386 and in case of a 64-bit target it has the value of x86_64.




回答2:


Here's how we do that:

win32 {
win32-g++:contains(QMAKE_HOST.arch, x86_64):{
    LIBS += ... #for win64
} else {
    LIBS += ... #for win32
}
}



回答3:


October 2016 update. 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.

greaterThan(QT_MAJOR_VERSION, 4) {
    TARGET_ARCH=$${QT_ARCH}
} else {
    TARGET_ARCH=$${QMAKE_HOST.arch}
}

contains(TARGET_ARCH, x86_64) {
    ARCHITECTURE = x64
} else {
    ARCHITECTURE = x86
}


来源:https://stackoverflow.com/questions/6579516/qt-creator-how-to-tell-win32-from-win64

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!