简体   繁体   English

如何使用基于Qt的依赖关系组织Qt DLL

[英]How to organize Qt DLLs with Qt-based dependency

I have a Qt application using Qt 4.8.5. 我有一个使用Qt 4.8.5的Qt应用程序。 This application is dependent on a DLL that was built using Qt 4.6.0. 此应用程序依赖于使用Qt 4.6.0构建的DLL。 Let's call it "MyDLL.dll". 我们称之为“MyDLL.dll”。

I cannot rebuild MyDLL.dll to update it to a more current version of Qt. 我无法重建MyDLL.dll以将其更新为更新版本的Qt。 Since both my application and MyDLL require the QtCore and other DLLs, and the versions are different, how do I organize my files such that they don't conflict? 由于我的应用程序和MyDLL都需要QtCore和其他DLL,并且版本不同,我如何组织我的文件以使它们不冲突?

MyDLL is required at startup, so I can't use any delay load methodologies. 启动时需要MyDLL,因此我无法使用任何延迟加载方法。

edit: To be clear, this question came up because the MyDll.dll was built using a custom Qt 4.6.0 from modified source, and my application is using a custom build of 4.8.5. 编辑:要清楚,这个问题出现了,因为MyDll.dll是使用自修改源的自定义Qt 4.6.0构建的,而我的应用程序使用的是4.8.5的自定义构建。 The modifications weren't necessarily the same in both versions, so I didn't want to assume that I could still use the 4.8.5 DLLs. 这两个版本的修改不一定相同,所以我不想假设我仍然可以使用4.8.5 DLL。 Turned out that it worked out in this case, but the question stands. 结果证明它在这种情况下有用,但问题就在于此。

Welcome to DLL Hell! 欢迎来到DLL地狱! :( :(

This is a huge problem under Microsoft windows, since the standard isn't to build version information into the DLL file name (like with Linux .so files). 这是Microsoft Windows下的一个大问题,因为标准不是将版本信息构建到DLL文件名中(就像Linux .so文件一样)。

You won't be able to accomplish what you are after if you link directly against "MyDLL.dll" since it will be looking for QT DLLs (like QtCore, QtGui, etc). 如果你直接链接“MyDLL.dll”,你将无法完成你所追求的,因为它将寻找QT DLL(如QtCore,QtGui等)。 The stock Qt DLLs contain no version decoration in the filename, so there will be a conflict as to which one to load. 库存Qt DLL在文件名中没有版本装饰,因此要加载哪一个会有冲突。 Also, you will likely not be able to link correctly in the first place (due to the conflicts. Qt doesn't play well with older versions). 此外,您可能无法在第一时间正确链接(由于冲突.Qt与旧版本不兼容)。

The only possibility might be to create a separate executable that links against Qt 4.6.0 and MyDLL, and use some out-of-process communication between your main app and the server. 唯一的可能是创建一个单独的可执行文件,链接Qt 4.6.0和MyDLL,并使用主应用程序和服务器之间的一些进程外通信。 COM might work in this case, but it largely depends on what your dll actually does. COM可能在这种情况下起作用,但它在很大程度上取决于你的dll实际上做了什么。

The only other course of action would be to downgrade your main application and fix it at Qt 4.6.0. 唯一的其他行动方案是降级您的主应用程序并将其修复为Qt 4.6.0。

You shouldn't be having any issues. 你不应该有任何问题。 Qt maintains binary compatibility over minor and patch releases (see http://qt-project.org/wiki/Qt-Version-Compatibility ) and an application/DLL built with 4.6.x will run fine when bound to 4.8.x runtime. Qt维护次要版本和补丁版本的二进制兼容性(请参阅http://qt-project.org/wiki/Qt-Version-Compatibility ),使用4.6.x构建的应用程序/ DLL在绑定到4.8.x运行时时运行正常。

  • Your MyDLL.dll built with 4.6.0 will run with 4.8.5 runtime DLLs. 使用4.6.0构建的MyDLL.dll将运行4.8.5运行时DLL。
  • Your application built with 4.8.5 will run with 4.8.5 runtime DLLs. 使用4.8.5构建的应用程序将运行4.8.5运行时DLL。
  • Your application will run fine with MyDLL.dll as long as you are using the same interface you've always been using. 只要您使用的是您一直使用的相同界面,您的应用程序就能正常运行MyDLL.dll。

If you are seeing issues it is because of something else, and you will need to clarify exactly what problem you are having. 如果您发现问题是因为其他原因,您需要明确说明您遇到的问题。

If you are not seeing issues and are just asking preemptively, then 1) just proceed as normal with no special considerations, and 2) you should have tried it first! 如果你没有看到问题并且只是先发制人地问,那么1)正常进行而没有特别的考虑,2)你应该先尝试一下!

Jason C's answer got it right. Jason C的回答是正确的。 Also note the following: 另请注意以下事项:

  1. MyDll.dll must be compiled with the same compiler version as the rest of your application. 必须使用与应用程序其余部分相同的编译器版本编译MyDll.dll。

  2. The version of Qt used to build MyDll.dll should have had the same major configuration flags as the version of Qt that you're currently using. 用于构建MyDll.dll的Qt版本应该具有与您当前使用的Qt版本相同的主要配置标志。 Things such as Qt namespaces, QThread support, etc. must all be the same. 诸如Qt名称空间,QThread支持等等都必须相同。

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

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