問題描述
原始問題略有不同,但屬于更重要問題的一部分.
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?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!