Windows 上的 Qt DLL 部署
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/868423/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Qt DLL deployment on Windows
提问by Paul Baumer
I have a Plug-in for an application from another company. My plug-in uses Qt so it needs the Qt DLLs. My problem is that all versions of 4.x Qt Dlls are called the same, e.g. :QtCore4.dll. It is quite possible that some other plugin, or another application which inserted itself into the PATH environment variable, has put Qt dlls in the applications folder. In that case, the plug-in will not start as it is expecting a different version of the DLL.
我有另一个公司的应用程序插件。我的插件使用 Qt,所以它需要 Qt DLL。我的问题是所有版本的 4.x Qt Dll 都被称为相同的,例如:QtCore4.dll。很可能其他插件或其他将自身插入到 PATH 环境变量中的应用程序已将 Qt dll 放在应用程序文件夹中。在这种情况下,插件将不会启动,因为它需要不同版本的 DLL。
- Q1. What is the suggested common practice for DLL deployment ?
- Q2. What if the host application uses a different version of Qt. Would windows allow the host application and the plug-in to use different versions () ?
- 一季度。建议的 DLL 部署常见做法是什么?
- Q2。如果宿主应用程序使用不同版本的 Qt 会怎样。windows 是否允许宿主应用程序和插件使用不同的版本 () ?
Thanks!
谢谢!
回答by Klathzazt
A1: Best practice: put the DLL in the directory of the executable. It will look there first for loading the DLL. This is common practice.
A1:最佳实践:将 DLL 放在可执行文件的目录中。它将首先在那里查找以加载 DLL。这是常见的做法。
A2: If somehow the application uses a different version of Qt and the module you are describint requires a later or specific version, it might cause a problem (not work, crash, etc).
A2:如果应用程序以某种方式使用了不同版本的 Qt,而您所描述的模块需要更高版本或特定版本,则可能会导致问题(不工作、崩溃等)。
With static Linking you would also have to consider license restrictions of Qt. LGPL is happy as long as the library is dynamically loaded at runtime and can be separated from the application. This only applies if you do not release your source, etc.
使用静态链接,您还必须考虑 Qt 的许可限制。只要库在运行时动态加载并且可以与应用程序分离,LGPL 就很高兴。这仅适用于您不发布源等的情况。
Also, your installer should set up access to those files so that they are protected from being overwritten by some other rogue application.
此外,您的安装程序应设置对这些文件的访问权限,以防止它们被其他恶意应用程序覆盖。
回答by nobody
Just to help others with this problem: QT DLL's are guaranteed to be the same (or at least binary compatible) for all 4.X Versions. (same for all 3.X Versions and so on) so there will be no Problem. This is also the reason wy there is no second number in the Qt dll naming.
只是为了帮助其他人解决这个问题:QT DLL 保证对于所有 4.X 版本都是相同的(或至少二进制兼容)。(所有 3.X 版本等都相同)所以不会有问题。这也是 Qt dll 命名中没有第二个数字的原因。
回答by ewall
With versions of Windows since XP (i.e. XP, 2003, Vista, 2008, and Win7), you can use the side-by-side assembliesor DLL redirection. In either case, essentially what you're doing is including a small text file that tells the operating system that you need to use the specific version of the DLLs you included in the same directory as the executable.
对于 XP 之后的 Windows 版本(即 XP、2003、Vista、2008 和 Win7),您可以使用并行程序集或DLL 重定向。在任何一种情况下,本质上您所做的都是包含一个小文本文件,该文件告诉操作系统您需要使用与可执行文件位于同一目录中的特定版本的 DLL。
These are lesser-known features, but they can really save your butt from "DLL Hell".
这些是鲜为人知的功能,但它们确实可以让您远离“DLL 地狱”。
回答by adlag
For safety you must be sure that your application uses the dll versions you want it to use. Windows is guaranteed to look in the application folder first. So there you should put all your binary dependencies.
为了安全起见,您必须确保您的应用程序使用您希望它使用的 dll 版本。Windows 保证首先查看应用程序文件夹。所以你应该把所有的二进制依赖项放在那里。
If your app does not run when you double click on it in explorer Windows will tell you what dll it needs. Copy that dll to the application folder. Go to the next step if your application runs.
如果在资源管理器中双击应用程序时应用程序没有运行,Windows 会告诉您它需要什么 dll。将该dll复制到应用程序文件夹。如果您的应用程序运行,请转到下一步。
Now you should temporarily remove (or rename) the dll's one by one that you have put in the application folder and each time you should double click your application. If Windows does not complain it found the dll somewhere else. Get that dll out of the PATH environment (possibly temporarily). Rapid Environment Editor is a free utility with edits environment variables which take effect immediately.
现在你应该暂时删除(或重命名)你已经放在应用程序文件夹中的 dll,每次你应该双击你的应用程序。如果 Windows 没有抱怨,它会在其他地方找到 dll。从 PATH 环境中获取该 dll(可能是暂时的)。Rapid Environment Editor 是一个免费实用程序,可以编辑立即生效的环境变量。
Only if you are sure your application uses the dll's in the application dir and does not pull in any dll from somewhere else you can start editing the PATH variable again to restore the old situation.
只有当您确定您的应用程序使用应用程序目录中的 dll 并且没有从其他地方提取任何 dll 时,您才能再次开始编辑 PATH 变量以恢复旧情况。
回答by Tim
Is there no way to choose to link statically with Qt?
有没有办法选择与Qt静态链接?
I would deploy the DLLs in the same directory as my app/plugin.
我会将 DLL 部署在与我的应用程序/插件相同的目录中。
This does not answer your other concerns though.
但这并不能解决您的其他问题。
回答by Patrick McDaniel
Like Tim said you should deploy the DLL's in the same directory as the app/plugin you are making. I believe the PATH variable is not the first place your program will look for the QT4 dll so therefore if you deploy it in the same folder your app will pick up the one with your app and ignore any that are on the PATH.
就像 Tim 说的那样,您应该将 DLL 部署在与您正在制作的应用程序/插件相同的目录中。我相信 PATH 变量不是您的程序查找 QT4 dll 的第一个位置,因此如果您将它部署在同一文件夹中,您的应用程序将选择您的应用程序并忽略 PATH 上的任何变量。
Q1: In the past it seemed like everyone threw their DLLs in the system32 folder because they knew it was on the PATH and knew there program would be able to find it. From a user's point of view I find that very hard to clean up when I want to uninstall something. And now with the small price of storage I would say keep your DLLs with your app especially if they are like this where there could be multiple versions. While I'm no expert this is how I handle jar files for Java applications.
Q1:过去似乎每个人都将自己的 DLL 放在 system32 文件夹中,因为他们知道它在 PATH 中并且知道那里程序能够找到它。从用户的角度来看,当我想卸载某些东西时,我发现很难清理。现在,以较低的存储价格,我会说将您的 DLL 与您的应用程序一起保存,特别是如果它们是这样的,其中可能有多个版本。虽然我不是专家,但这就是我处理 Java 应用程序 jar 文件的方式。
Q2: I would think so. It would depend on the directory structure of the app and plugin. You can tell your plugin which version to use and I'm willing to bet the app has its version in a special place already as well.
Q2:我会这么认为。这将取决于应用程序和插件的目录结构。你可以告诉你的插件使用哪个版本,我敢打赌该应用程序也已经在一个特殊的地方有它的版本。