问题描述
原始问题略有不同,但属于更重要问题的一部分.
Original question was slightly different but part of a more major question.
我正在尝试在 Windows 上使用静态 OpenSSL 将 Qt 5.2 构建为静态的.
I am trying to build Qt 5.2 as static with static OpenSSL on Windows.
我的最终目标是发布单个二进制文件,而无需提供 libeay32.dll 和 ssleay32.dll.然而,在我看来这是不可能的.我使用静态 openssl 库构建了静态 Qt,但似乎 Qt 完全忽略了提供的库并始终搜索 DLL.
My final goal is to ship a single binary without the need to provide libeay32.dll and ssleay32.dll with it. However, it seems to me that this is impossible. I built static Qt with static openssl libs but it seems like Qt is outright ignoring the libs provided and always searches for DLLs.
这个答案还表明 QtNetwork 总是搜索 DLL 并忽略所有内容否则,但它也指出两个选项是将 OpenSSL 编译为 Qt...",但情况似乎并非如此.
This answer also suggests that QtNetwork always searches for DLLs and ignores everything else but it also states that "two options are to compile OpenSSL into Qt..." but this does not seem to be the case.
有人可以提供明确的答案吗?
Can someone provide a definitive answer?
这是我的 Qt 配置(为了可读性添加了换行符):
This is my Qt configure (line breaks added for readability):
configure -static -qmake -opensource -nomake examples -opengl desktop
-platform win32-msvc2010 -openssl -I C:gitopenssluildinclude
-L C:gitopenssluildlib OPENSSL_LIBS="-llibeay32 -lssleay32 -lgdi32"
推荐答案
有没有办法用静态 OpenSSL 构建静态 Qt?
Is there any way to building static Qt with static OpenSSL?
当然,你在配置Qt时需要使用以下选项:
Sure, you need to use the following option when configuring Qt:
-openssl-linked
原因是QtNetwork默认使用QLibrary
类来动态打开库以获取必要的符号.
The reason is that QtNetwork uses the QLibrary
class by default for dynamically opening the library to get the necessary symbols.
这是告诉Qt不要这样做的选项,并尊重正常的链接规则.
This is the option to tell Qt not to do so, and respect the the normal linkage rules.
话虽如此,如果需要在没有您参与的情况下为最终用户提供安全更新,则不建议对 openssl 使用静态链接.考虑一下,如果你离开了,不再从事这个项目,等等会发生什么.
That being said, it is not recommended to use static linkage for openssl if security updates need to be available for the end user without your involvement. Consider that for a moment what happens if you are gone, not working on this project anymore, etc.
此外,此设置未经过频繁测试,因此您实际上可能会遇到一些应该在上游修复的问题,但这是针对相关用例的解决方案设计.
Also, this setup is not tested frequently, so you may actually encounter some issues that should be fixed upstream, but this is solution design for the use case in question.
免责声明:由于 SO 是关于编程的,我忽略了对 Qt 静态链接的许可后果,所以我想快速提醒您注意正确使用,以免陷入法律麻烦.
Disclaimer: since SO is about programming, I am ignoring the licensing consequences for static linking againt Qt, so I would just like to quickly remind that you that be aware of the proper usage not to get into legal troubles.
这篇关于有没有办法用静态 OpenSSL 构建静态 Qt?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!