简体   繁体   English

如何静态构建Qt 5

[英]How to build Qt 5 statically

I worked with Qt Creator 2.6.2 based on Qt 5.0.1 in a linux environnement. 我在Linux环境中使用基于Qt 5.0.1的Qt Creator 2.6.2。 The application works fine on the computer where I made the compilation but when I execute it on another computer I got errors like : 应用程序在我编译的计算机上工作正常,但是当我在另一台计算机上执行它时,我得到的错误如下:

error while loading shared libraries: libQt5WebKitWidgets.so.5: cannot open shared object file: No such file or directory
error while loading shared libraries: libxslt.so.1: cannot open shared object file: No such file or directory

I found some solutions in this link (some links are dead). 我在这个链接中找到了一些解决方案(一些链接已经死了)。

So I added to my .pro file this line : 所以我在我的.pro文件中添加了这一行:

CONFIG += static

To compile my project statically. 静态编译我的项目。

I thought the file I'll get will be larger but I got the same size and the same errors. 我以为我得到的文件会更大,但我有相同的大小和相同的错误。

Thank you. 谢谢。

The Qt shared libraries don't exist on the other computer you tested it on. 在您测试它的另一台计算机上不存在Qt共享库。 So you need to either: 所以你需要:

  1. Copy the shared libraries to your other machine. 将共享库复制到其他计算机。 Or... 要么...
  2. Create a static Qt build to link with your application. 创建一个静态Qt构建以与您的应用程序链接。

It's not sufficient to just add CONFIG += static to your .pro file, you also need Qt static libraries. 仅将CONFIG += static添加到.pro文件中是不够的,还需要Qt静态库。 So to do #2 you'll need to get the Qt source code and build it yourself. 所以要做#2你需要获得Qt源代码并自己构建它。

Also, Qt is licensed under the LGPL so you'll need to be aware of that when static linking. 此外,Qt是根据LGPL许可的,因此在静态链接时您需要注意这一点。 There are some who believe that the LGPL does not allow static linking (unless you LGPL your own code) and others who believe that it does (so long as you're willing to release the object code for your app). 有些人认为LGPL不允许静态链接(除非你是LGPL自己的代码)和其他相信它的人(只要你愿意为你的应用程序发布目标代码)。 But that's a whole other discussion. 但这是另一个讨论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM