Question

I have a project I am working on, and need to be able to compile both 32bit and 64bit versions on linux. I have both 32 and 64bit versions of the Qt libraries installed, and use eclipse to do my work. Inside eclipse I can switch between the different Qt versions through the Qt properties menu in project properties. My question is this:

Since the machine is 64bit, QMAKESPEC is linux-g++-64 by default, even if I switch my qt libraries to the 32 bit versions, g++ still outputs 64bit object files- which I cannot link with other 32bit libraries. I know one can export the QMAKESPEC environment variable, and that works in the shell, but is it possible to do this within eclipse? So that when I run qmake within eclipse, the appropriate QMAKESPEC is applied?

Thank you in advance!

Was it helpful?

Solution

I have had to deal with this problem when doing some cross-compiling for multiple targets with Qt under Eclipse (really Momentics). I came up with 2 different ways. The first one was what I settled on, but here are they both are.

1) The first way is to start by creating the project as a normal CDT C/C++ project instead of a Qt project. QMake is then added as an External Tool (Run --> External Tools --> External Tools Configuration...) with Arguments specific for how to run qmake (e.g. '-r -unix -spec linux-g++-64 "CONFIG+=enableFeature"'). Multiple versions of the QMake external tool are used for different configurations. To change between them, the different external tools are invoked.

The advantage of this approach is that it gives very fine control of exactly how QMake is invoked and when it is invoked. The drawback is that the *.pro files are note automatically managed.

2) The other method I tried (and I think worked... YMMV) was with a Qt Project. Here, the QMAKESPEC is set as an environmental variable in the Project Properties under "C/C++ Make Project" under the "Environment" tab.

IIRC, the big issue I found here (and for which I filed a bug report) was that changing other properties would cause the QMAKESPEC to be "corrected" automatically back to another value for you. The practical implication is that you need to make sure it is the last thing set before clicking OK to close the Properties dialog.

OTHER TIPS

If the Qt-project is a regular CDT-project, you can open the project properties (select project in the Resource Explorer and hit "Project" -> "Properties"). Select the "C/C++ Build" -> "Environment" page and add your environment variables.

The other possibility is to add the "-m32" flag to the compiler and the linker, effectively telling it to produce 32 bit binaries (I suppose this will cause some problems with library paths, though).

All of this relates to the general C++-projects using Eclipse/CDT; I don't know how Qt-projects deviate from this mechanism.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top