在 OS X 和 Linux 上部署 QT 应用程序

发布于 2024-08-19 15:55:11 字数 118 浏览 7 评论 0原文

部署 QT 应用程序的最佳方式是什么?我已阅读 trolltech 托管的文档,但是链接静态库还是动态库并让用户安装框架更好?我真的不希望使用我的应用程序的任何人都必须下载 160mb 的框架才能运行简单的 GUI 前端。

Whats the best way to deploy a QT app? I've read the documentation hosted at trolltech but is it better to link with a static library or the dynamic libraries and have the user install the framework? I don't really want anyone using my app to have to download a 160mb framework just to run a simple gui frontend.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

瞎闹 2024-08-26 15:55:11

在 OS X 上,这是使用 Qt 从 4.5 开始附带的 macdeployqt 工具进行动态构建和后处理生成的“.app”的好方法。

这会将应用程序使用的 Qt 框架复制到应用程序包中,从而生成比构建应用程序的静态版本更大的包。

您可以采取以下措施来确保在动态构建中获得尽可能小的文件大小:

  • 首先,确保只包含您需要的内容(在project.pro文件的QT += core gui network xml中) 行)。
  • 打开应用程序包并从包中删除任何不需要的“Qt 插件”。 macdeployqt 自动编译其中的所有 Qt 插件,这可能有点庞大。
  • 确保您在发布模式下构建应用程序。否则,您的应用程序可能会链接到 Qt4 框架的调试库,而且它们真的很大(例如,调试库远超过 90 MB,而调试库则为 16 MB)没有调试符号的发行版变体)。这可能就是您的情况所发生的情况。
  • 如果您有大型应用程序二进制文件,则可以使用 UPX 将可执行文件压缩 40-50%。

除此之外,您应该使用压缩磁盘映像来部署应用程序。

我的一个项目使用 QtGuiQtNetworkQtCoreQtXml,生成的包大小约为 16 MB 。

希望有帮助。

On OS X it's a good way to do a dynamic build and post-process the resulting ".app" with the macdeployqt tool which comes with Qt starting with 4.5.

This will copy the Qt frameworks used by your application into the application bundle, which results in a larger package than building a static version of your application.

Here is what you can do to make sure you get the smallest file size possibly in a dynamic build:

  • First off, make sure you only include the stuff you need (in the project.pro file's QT += core gui network xml lines).
  • Open the application bundle and remove any unneeded "Qt Plugins" from the bundle. macdeployqt automatically compies all the Qt plugins in there, which can be kind of bulky.
  • Make sure you are building your application in release mode. Otherwise your application might be linked against the debug libraries of the Qt4 framework, and they are really big (for instance, well over 90 MB for the debug library vs. 16 MB of a release variant without debugging symbols). This might be what happened in your case.
  • If you have a large application binary, you can use UPX to compress your executable file by 40-50%.

Other than that, you should use compressed disk images to deploy your application.

One of my projects uses QtGui, QtNetwork, QtCore and QtXml and the resulting bundle is about 16 MB in size.

Hope that helps.

山人契 2024-08-26 15:55:11

不幸的是,您必须将所需的 Qt 库包含到您自己的捆绑包中,因为您不能指望您的用户在 Mac 上安装 Qt(而在 Linux 打包系统上允许您至少需要给定版本的 Qt。

有一个很好的解决方案一个名为 macdeployqt 的工具可以帮助您完成此任务,您只需在捆绑应用程序上调用它,它就会打包所需的库,并更改二进制文件的链接以引用它们。真正的痛苦(仍然如此,但要少得多)

。 >http://doc.trolltech.com/4.6/deployment-mac.html#the-mac-deployment-tool

然后,您可以像使用任何其他应用程序一样制作 .dmg 映像。 macdeployqt 中构建基本选项的一个选项。

Unfortunately you will have to include the Qt libraries you need into your own bundle, as you cannot expect your users to have Qt installed on Mac (whereas on Linux packaging systems allow you to require at least a given version of Qt.

There is a nice tool to help you with that, which is called macdeployqt. You just need to invoke it on your bundle application and it will pack the required libraries, changing the linkage of your binary to refer to them. Without it, making bundles for Mac is a real pain (it still is, but considerably less though).

http://doc.trolltech.com/4.6/deployment-mac.html#the-mac-deployment-tool

Afterwards, you can make a .dmg image as you would do with any other app. There is an option in macdeployqt that builds a basic one.

魄砕の薆 2024-08-26 15:55:11

在 Linux 上,最好依赖操作系统的 Qt 副本,因为它几乎肯定已安装 - 对于 OS X,几乎所有应用程序都使用静态编译的库。

On Linux, it's better to rely on the OS's copy of Qt, as it's almost certainly installed - for OS X, almost all apps use a statically compiled library.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文