windows Qmake 中 win64 配置的标识符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/356666/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Identifier for win64 configuration in Qmake
提问by Tuminoid
Is there a "win64" identifier in Qmake project files? Qt Qmake advanceddocumentation does not mention other than unix / macx / win32.
Qmake 项目文件中是否有“win64”标识符?Qt Qmake 高级文档除了 unix/macx/win32 之外没有提到。
So far I've tried using:
到目前为止,我已经尝试使用:
win32:message("using win32")
win64:message("using win64")
amd64:message("using amd64")
The result is always "using win32".
结果总是“使用win32”。
Must I use a separate project-file for x32 and x64 projects, so they would compile against correct libraries? Is there any other way to identify between 32-bit and 64-bit environments?
我是否必须为 x32 和 x64 项目使用单独的项目文件,以便它们可以针对正确的库进行编译?有没有其他方法可以识别 32 位和 64 位环境?
回答by did
I do it like this
我这样做
win32 {
## Windows common build here
!contains(QMAKE_TARGET.arch, x86_64) {
message("x86 build")
## Windows x86 (32bit) specific build here
} else {
message("x86_64 build")
## Windows x64 (64bit) specific build here
}
}
回答by Nejat
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:
从 Qt5 开始,您可以使用QT_ARCH
来检测您的配置是 32 位还是 64 位。当目标是 32 位时,它返回i386
,如果是 64 位目标,它的值为x86_64
。所以它可以像这样使用:
contains(QT_ARCH, i386) {
message("32-bit")
} else {
message("64-bit")
}
回答by rubenvb
UPDATE: since very recently, Qt has a way of doing this transparently and easily, without manual hassle:
更新:从最近开始,Qt 有一种透明且轻松的方法,无需手动操作:
win32-g++:contains(QMAKE_HOST.arch, x86_64):{
do something
}
Source: the brand new Qt Dev FAQ
回答by Tuminoid
I've figured out one way to do it.
我想出了一种方法来做到这一点。
Qt allows you to pass arbitrary config parameters which you can use to separate the targets.
Qt 允许您传递可用于分隔目标的任意配置参数。
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
with
qmake CONFIG+=myX64
you get the wanted result.
你得到想要的结果。
回答by Reed Hedges
No, but you can create and use a new mkspec, I think qmake also defines a platform identifier named after the current mkspec. Why do you need to test for 64 bit?
不,但您可以创建和使用新的 mkspec,我认为 qmake 还定义了一个以当前 mkspec 命名的平台标识符。为什么需要测试64位?
Reed
芦苇