How can I detect in the .pro file if I am compiling for a 32 bit or a 64 bit platform?

You can use QMAKE_TARGET.arch to decide the platform you are building for. You can do it as follows:

  1. win32-msvc*:contains(QMAKE_TARGET.arch, x86_64):{
  2. message( "Building for 64 bit")
  3. }

4 comments

June 14, 2011

Picture of ludde ludde

Ant Farmer

This seems to be available only on Windows, not on Linux.
Would it not be useful on Linux as well?

June 15, 2011

Picture of zenoalbisser zenoalbisser

Lab Rat

Hi,

This is currently a windows/msvc only solution, that is true.
The reason for that is, that on windows you usually build from a visual studio command prompt which allows you to easily figure out the target platform by checking the environment.
On Linux there is no need for a specific build environment and therefor we cannot rely on specific environment variables. The only way to figure out which compiler will be used would be to fire up the compiler itself and “ask” for the target platform. Such a solution is currently too cumbersome and expensive for being used in the .pro parser.
What is the use case for this? – Am i missing something?

June 16, 2011

Picture of ludde ludde

Ant Farmer

To be honest I’m not sure there is a use case… :)
I just tried to use it on Linux, to differentiate between 32 and 64 bit builds, and was a bit surprised when it didn’t work. But I’m not sure we will ever do 32/64-bit cross compilation on Linux, so using QMAKE_HOST.arch will work just as well. Or, we could (and probably should) use the mkspecs (linux-g++-32 and linux-g++-64) to differentiate between the target platforms.

October 31, 2012

Picture of tvogel tvogel

Lab Rat

Cross-compiling for 32 bit on an 64 bit host is really not uncommon on Linux, I think. I am using

  1. linux-g++:QMAKE_TARGET.arch = $$QMAKE_HOST.arch
  2. linux-g++-32:QMAKE_TARGET.arch = x86
  3. linux-g++-64:QMAKE_TARGET.arch = x86_64

Write a comment

Sorry, you must be logged in to post a comment.