Windows 下 Qt 应用程序的编译发行版

发布于 2024-10-05 02:15:26 字数 116 浏览 0 评论 0原文

我成功地编译并运行了我的 Qt 应用程序。然而,当我将.exe文件移出其原始路径时,我发现我必须手动复制Qt DLL(例如mingw10.dll、qtcore4.dll)。是否有任何动态方式将这些库与我的应用程序链接?

I was successfully able to compile and run my Qt application. However, when I move the .exe file outside its original path, I found out that I have to manually copy the Qt DLLs (e.g. mingw10.dll, qtcore4.dll). Is there any dynamic way to link these libraries with my application?

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

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

发布评论

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

评论(2

雨后彩虹 2024-10-12 02:15:26

我认为您的意思是您想要将这些库“静态”链接到您的应用程序。
基本上,这意味着所有内容都将包含在您的 exe 中,并且您将不再需要这些 dll。

静态链接有优点,但也有缺点。在走这条路之前,你应该绝对确定这就是你想要做的事情。

查看此链接,它解释了深度差异动态链接与静态链接

至于您的具体问题,如果您确定要使用静态链接,则必须将 Qt 设置更改为静态构建。默认情况下,Qt 发行版设置为使用动态链接。 此处有一个方便的指南。

基本上,当您设置构建时,您必须运行“configure -static”来更改所有项目设置以使用静态链接而不是动态链接。然后重新构建 Qt。

您还应该验证您的 Qt 许可证。如果您使用 Qt LGPL 许可证并且想要静态链接,则必须包含所有目标文件(.o 和 .obj),正如 Mihai Limbăşan 在他的评论中明智地解释的那样。如果您已经购买并支付了 Qt,那么就没有问题。

I think you mean you want to "statically" link these libraries with your application.
Basically this means that everything will be rolled inside your exe, and you will have no need of those dlls anymore.

There are advantages to to static linking, but there are also disadvantages as well. You should be absolutely sure that this is what you want to do before you go this way.

Check out this link which explains the difference in depth Dynamic Linking vs Static Linking

As for your specific issue, if you are sure you want to use static linking you will have to change your Qt setup to be built statically. By default the Qt distribution is setup to use dynamic linking. There is a handy guide for that here.

Basically when you setup the build you have to run "configure -static" to change all the project settings to use static linking instead of dynamic linking. And then build Qt over again.

You should also verify your Qt license. If you are using the Qt LGPL license and you want to to link statically you will have to include all your object files (.o and .obj) as Mihai Limbășan wisely explained in his comment. If you have bought and paid for Qt, then you have no problem.

昇り龍 2024-10-12 02:15:26

如果 DLL 位于应用程序的 PATH 上,那么它们将被找到并工作。因此,您可以将 Qt 二进制文件/dll 的位置添加到 %PATH% 环境变量中。如果您要为应用程序创建安装程序,则需要将这些库打包到 bin 目录中 - 或者您必须期望每个用户自己安装并可能编译 Qt(提示: 选择第一个选项:) )

If the DLLs are on the PATH for the application, then they will be found and work. So, you could add where your Qt binaries/dlls are into the %PATH% environment variable. If you're going to create an installer for your application, you'll need to either package these libraries in so they're in the bin directory - or you'll have to expect every user to install and possibly compile Qt themselves (hint: go with the first option. :) )

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