从 eclipse 中更改 QMAKESPEC?
我正在开发一个项目,需要能够在 Linux 上编译 32 位和 64 位版本。我安装了 32 位和 64 位版本的 Qt 库,并使用 eclipse 来完成我的工作。在 Eclipse 中,我可以通过项目属性中的 Qt 属性菜单在不同的 Qt 版本之间切换。我的问题是这样的:
由于机器是64位,QMAKESPEC默认是linux-g++-64,即使我将qt库切换到32位版本,g++仍然输出64位目标文件 - 我无法与其他32位库链接。我知道可以导出 QMAKESPEC 环境变量,并且可以在 shell 中使用,但是可以在 eclipse 中执行此操作吗?这样当我在 eclipse 中运行 qmake 时,就会应用适当的 QMAKESPEC?
先感谢您!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当我在 Eclipse(真正的 Momentics)下使用 Qt 对多个目标进行交叉编译时,我不得不处理这个问题。我想出了两种不同的方法。第一个是我决定的,但它们都是。
1) 第一种方法是首先将项目创建为普通 CDT C/C++ 项目而不是 Qt 项目。然后将 QMake 添加为外部工具(运行 --> 外部工具 --> 外部工具配置...),并带有特定于如何运行 qmake 的参数(例如 '-r -unix -spec linux-g++-64 " CONFIG+=启用功能"')。多个版本的 QMake 外部工具用于不同的配置。要在它们之间进行更改,需要调用不同的外部工具。
这种方法的优点是它可以非常精细地控制 QMake 的调用方式和调用时间。缺点是 *.pro 文件是自动管理的。
2)我尝试过的另一种方法(我认为有效...... YMMV)是使用 Qt 项目。此处,QMAKESPEC 在“环境”选项卡下的“C/C++ Make Project”下的“项目属性”中设置为环境变量。
IIRC,我在这里发现的大问题(我为此提交了错误报告)是更改其他属性会导致 QMAKESPEC 自动“更正”回另一个值。实际含义是,您需要确保它是最后设置的内容,然后单击“确定”关闭“属性”对话框。
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.
如果 Qt 项目是常规 CDT 项目,您可以打开项目属性(在资源浏览器中选择项目并点击“项目”->“属性”)。选择“C/C++构建”-> “环境”页面并添加您的环境变量。
另一种可能性是向编译器和链接器添加“-m32”标志,有效地告诉它生成 32 位二进制文件(不过,我认为这会导致库路径出现一些问题)。
所有这些都与使用 Eclipse/CDT 的一般 C++ 项目相关;我不知道 Qt 项目如何偏离这种机制。
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.