使用Qt进行静态构建(独立应用程序) [英] Making static Build(standalone application) with Qt

查看:423
本文介绍了使用Qt进行静态构建(独立应用程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始用Qt回来。我已经下载了windows 32bit版本(666mB),没有别的。我做了一个简单的计算器应用程序。
该应用程序运行时,我从Qt creator运行它,但构建的exe显示DLL丢失。
我不想使用依赖关系walker我想创建一个静态构建(我读它,但我不能让它运行)



<我的目标是使一个功能齐全的计算器(无安装程序),而无需手动添加依赖关系。
我已经阅读过关于configure -static,但是我不明白如何使用它。
预先感谢您的帮助。

解决方案

您需要从源代码构建Qt。您将确实想要维护两个Qt版本。对于调试,您应该使用共享构建,因为这具有合理的链接时间。对于发布,你应该使用静态构建,绝对与链接时间代码生成保持可执行文件更小,并期望构建一个简单的应用程序采取一分钟的数量级。这是因为链接真的生成Qt和您的应用程序的机器代码,并且该代码是特定于您的应用程序,从而使它通常表现更好。



方式你做它不浪费磁盘空间的多个副本的源是通过使用源代码外的Qt构建。到目前为止静态的Qt 5.1.1构建是破碎的,所以下面只适用于Qt 4,与Visual Studio。


  1. 下载源文件,例如 C:\Qt\4.8.5


  2. 创建 C:\Qt\4.8.5-shared 。打开Visual Studio控制台,光盘,并运行 C:\Qt\4.8.5\configure.exe -shared 与任何其他选项,你可能有。然后使用 nmake jom 建立。


  3. p>创建 C:\Qt\4.8.5-static 。打开Visual Studio控制台,光盘,并运行 C:\Qt\4.8.5\configure.exe -static -ltcg 与任何其他选项,你可能有。然后使用 nmake jom 构建它。


您需要链接插件静态到您的发布版本的应用程序



Qt Creator可以轻松地并行使用多个构建的Qt。我常规使用Qt 4和Qt 5,静态和共享,与本地修复Qt 5的构建使静态构建工作。


I started out with Qt a while back. I have downloaded the windows 32bit version(666mB),and nothing else. I have made a simple calculator app. The app runs when I run it from Qt creator, but the built exe shows dlls missing. I don't want to use dependency walker.I want to create a static build(I read about it , but I am not able to get it running)

My objective is to make a fully functional calculator (no installer), without having to manually add the dependencies. I have read about the configure -static, but I didn't understand how to use it. Thanks in advance for the help.

解决方案

You need to build Qt yourself from source. You will definitely want to maintain two builds of Qt. For debugging, you should use the shared build, as this has reasonable link times. For release, you should use the static build, definitely with link time code generation to keep the executable smaller, and expect the build of a trivial application to take on the order of a minute. This is because the "link" really generates machine code for both Qt and your application, and the code is specific to your application, thus making it generally perform better.

The way you do it without wasting disk space for multiple copies of the source is by using out-of-source Qt builds. So far the static Qt 5.1.1 build is broken, so the below only works for Qt 4, with Visual Studio.

  1. Download the source to, say, C:\Qt\4.8.5.

  2. Create C:\Qt\4.8.5-shared. Open the visual studio console, CD there, and run C:\Qt\4.8.5\configure.exe -shared with whatever other options you may have. Then build it using nmake or jom.

  3. Create C:\Qt\4.8.5-static. Open the visual studio console, CD there, and run C:\Qt\4.8.5\configure.exe -static -ltcg with whatever other options you may have. Then build it using nmake or jom.

You'll need to link the plugins statically to your release build of the application.

Qt Creator makes it easy to use multiple builds of Qt in parallel. I routinely do builds using both Qt 4 and Qt 5, both static and shared, with local fixes to Qt 5 to get the static build to work.

这篇关于使用Qt进行静态构建(独立应用程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆