Visual Studio 编译的 Qt 插件在发布模式下无法加载

发布于 2024-09-10 14:21:33 字数 2689 浏览 3 评论 0原文

我正在开发 Qt 应用程序和 Qt 插件库。就我使用调试模式而言,一切工作正常。

然而,当我尝试在发布模式下编译时,插件不会加载。我从 QPluginLoader 收到以下错误消息:

预期的构建密钥“Windows msvc release full-config”得到了“Windows msvc debug full-config”。

我已经检查了 Visual Studio 2005 中的所有项目配置设置,它们都处于发布模式并且没有调试符号。编译器的输出还指出:

1>------ 全部重建已开始:项目:ExtraAnalysisTools,配置:Release Win32 ------ 1>删除项目“ExtraAnalysisTools”的中间和输出文件,配置“Release|Win32”

所以我不知道还要做什么。我尝试使用 Dependency Walker,但由于某种原因它无法加载文件(抱歉输出是日语......)

最后,这是我用来生成插件项目的 .pro 文件

模板=库
CONFIG += 插件
CONFIG += debug_and_release
包含路径 += ../
标头 = ExtraAnalysisTools.h
来源 = ExtraAnalysisTools.cpp
目标 = AKL_ExtraAnalysisTools
DESTDIR = ./

build_pass:CONFIG(调试、调试|发布) {
unix: TARGET = $$join(TARGET,,,_debug)
否则: TARGET = $$join(TARGET,,,d)
}
CONFIG(调试,调试|发布):message("调试模式")
CONFIG(release,debug|release):message("发布模式")
消息( CONFIG = $$CONFIG )

更新:我现在使用这个 .pro 文件并获得以下输出:

[1] - 项目消息:调试模式
[2] - 项目消息:CONFIG = lex yacc warn_on 调试 uic 资源 rtti_off exceptes_off stl_off 增量_off thread_off windows qt warn_on 释放增量平 link_prl precompile_header autogen_precompile_source copy_dir_files debug_and_release debug_and_release_target embed_manifest_dll embed_manifest_exe 调试共享 stl 异常 rtti mmx 3dnow sse2 def_files 插件 debug_and_release
[3] - 项目消息:调试模式
[4] - 项目消息:CONFIG = lex yacc warn_on 调试 uic 资源 rtti_off exceptes_off stl_off增量_off thread_off windows debug DebugBuild 调试 build_pass qt warn_on 释放增量平 link_prl precompile_header autogen_precompile_source copy_dir_files debug_and_release debug_and_release_target embed_manifest_dll embed_manifest_exe 调试共享 stl 异常 rtti mmx 3dnow sse sse2 def_files 调试 DebugBuild调试 build_pass 插件 debug_and_release
[5] - 项目消息:发布模式
[6] - 项目消息:CONFIG = lex yacc warn_on debug uic resources rtti_off exceptes_off stl_offincremental_off thread_off windows release ReleaseBuild Release build_pass qt warn_on releaseincremental flat link_prl precompile_header autogen_precompile_source copy_dir_files debug_and_release debug_and_release_target embed_manifest_dll embed_manifest_exe 调试< /strong> 共享 stl 异常 rtti mmx 3dnow sse sse2 def_files 发布 ReleaseBuild 发布 build_pass 插件 debug_and_release

我注意到发布模式下的debug标志,所以我还尝试添加CONFIG -= debug和CONFIG -=调试 debug 我的 .pro 文件(也与 += release 和 += debug_and_release 结合使用)。但这没有用。

我希望通过这些额外的信息我们能够更接近问题。

非常感谢!这让我发疯 xP

I am developing a Qt application and a Qt Plugin library. Everything is working fine as far as I use the debug mode.

Nevertheless, when I try to compile in release mode the plugin doesn't load. I got the following error message from QPluginLoader:

Expected build key "Windows msvc release full-config" got "Windows msvc debug full-config".

I have checked all my project configuration settings in Visual Studio 2005, and they are all in release mode and without debug symbols. Also the output of the compiler states that:

1>------ Rebuild All started: Project: ExtraAnalysisTools, Configuration: Release Win32 ------
1>Deleting intermediate and output files for project 'ExtraAnalysisTools', configuration 'Release|Win32'

So I don't know what more to do. I tried to use Dependency Walker, but for some reason it cannot load the file (sorry the output is in Japanese...)

Finally, here is the .pro file I use to generate the plugin project

TEMPLATE = lib
CONFIG += plugin
CONFIG += debug_and_release
INCLUDEPATH += ../
HEADERS = ExtraAnalysisTools.h
SOURCES = ExtraAnalysisTools.cpp
TARGET = AKL_ExtraAnalysisTools
DESTDIR = ./

build_pass:CONFIG(debug, debug|release) {
unix: TARGET = $$join(TARGET,,,_debug)
else: TARGET = $$join(TARGET,,,d)
}
CONFIG(debug,debug|release):message("Debug mode")
CONFIG(release,debug|release):message("Release mode")
message( CONFIG = $$CONFIG )

Update: I use now this .pro file and get the following output:

[1] - Project MESSAGE: Debug mode
[2] - Project MESSAGE: CONFIG = lex yacc warn_on debug uic resources rtti_off exceptions_off stl_off incremental_off thread_off windows qt warn_on release incremental flat link_prl precompile_header autogen_precompile_source copy_dir_files debug_and_release debug_and_release_target embed_manifest_dll embed_manifest_exe debug shared stl exceptions rtti mmx 3dnow sse sse2 def_files plugin debug_and_release
[3] - Project MESSAGE: Debug mode
[4] - Project MESSAGE: CONFIG = lex yacc warn_on debug uic resources rtti_off exceptions_off stl_off incremental_off thread_off windows debug DebugBuild Debug build_pass qt warn_on release incremental flat link_prl precompile_header autogen_precompile_source copy_dir_files debug_and_release debug_and_release_target embed_manifest_dll embed_manifest_exe debug shared stl exceptions rtti mmx 3dnow sse sse2 def_files debug DebugBuild Debug build_pass plugin debug_and_release
[5] - Project MESSAGE: Release mode
[6] - Project MESSAGE: CONFIG = lex yacc warn_on debug uic resources rtti_off exceptions_off stl_off incremental_off thread_off windows release ReleaseBuild Release build_pass qt warn_on release incremental flat link_prl precompile_header autogen_precompile_source copy_dir_files debug_and_release debug_and_release_target embed_manifest_dll embed_manifest_exe debug shared stl exceptions rtti mmx 3dnow sse sse2 def_files release ReleaseBuild Release build_pass plugin debug_and_release

I noticed the debug flags in the released mode, so I also tried to add the CONFIG -= debug and CONFIG -= Debug debug to my .pro file (also combining with += release and += debug_and_release). But it didn't work.

I hope with this extra information we can get closer to the problem.

Thank you very much! It's driving me crazy xP

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

箹锭⒈辈孓 2024-09-17 14:21:33

如果您使用调试库编译插件并使用发布库编译 EXE,您将收到此错误。解决方案是确保您的可执行文件和 dll 使用相同的配置(发布或调试)进行编译。

在 Visual Studio 中,在项目设置下,您可以检查链接器 -> 输入并确保列出的库缺少“d”后缀(QtCored4.dll 是调试,QtCore4.dll 是发布)。

Creator 中的 .pro 文件有点棘手,因为始终定义调试(发布“覆盖”调试)。 Qt make 文档中到处都有关于使用 debug_and_release 的警告。我建议一次只编译一个或另一个 - 在我看来,该标志带来的额外麻烦是不值得的。

You'll get this error if you compile your plugin's with the debug libraries and your EXE with the release libraries. The solution is to make sure your executable and dll's are compiled with the same configuration (release or debug).

In visual studio, under the project settings, you can check Linker ->Input and make sure the libraries listed there are missing the "d" suffix (QtCored4.dll is debug, QtCore4.dll is release).

The .pro files in Creator are a little trickier, since debug is always defined (release "overrides" debug). there warnings all over the Qt make documentation about using debug_and_release. I would recommend just compiling one or the other at a time - the extra trouble of that flag just isn't worth it, imo.

小镇女孩 2024-09-17 14:21:33

我猜你的发布配置中缺少 QT_NO_DEBUG 预处理器标志。这就是为什么您的“发布”构建会通过“调试”模式获取插件构建密钥。而且您的解决方法确实“令人讨厌”,因为每次修改插件后都会重新创建插件的注册表项

I gues you are lacking of QT_NO_DEBUG preprocessor flag in you release configuration. That's why your "release" build gets plugin build key with "debug" mode. And your workaround is realy "nasty", because registry entries for plugins are recreated after each plugin modification

千纸鹤 2024-09-17 14:21:33

将以下行添加到您的 .pro 文件并查看它将打印什么。显式的 CONFIG += 发布有点可疑。请记住,如果调试已在 CONFIG 中,它将覆盖发布。

CONFIG(debug,debug|release):message("Debug mode")
CONFIG(release,debug|release):message("Release mode")

如果它打印这两个条目,则其他地方可能已经存在 CONFIG += debug。

Add the following lines to your .pro file and see what it will print. The explicit CONFIG += release is kinda fishy. Remember that if debug is already in CONFIG, it overrides release.

CONFIG(debug,debug|release):message("Debug mode")
CONFIG(release,debug|release):message("Release mode")

If it prints both entries, there might already be a CONFIG += debug elsewhere.

梅窗月明清似水 2024-09-17 14:21:33

嗯,实际上这只是与 Visual Studio 配置相关的问题。我正在重新安排我的项目设置以包含一个新的共享库,突然它起作用了...

尽管我正在使用调试和发布来编译插件的不同版本,但由于 qmake 项目文件,我用来将正确的 Qt 标志导入到项目中,目标文件夹对于两个版本都是通用的,可能混合了一些中间文件(dll 文件不同)。

我不确定这是否是真正的原因 100%,但如果您遇到与此类似的另一个问题,请首先尝试使用不同的目标目录。

Well, actually it was a problem only related to Visual Studio configuration. I was rearranging my project setup to include a new shared library and suddenly it worked...

Although I was compiling different versions of the plugin using debug and release, because of the qmake project file I used to import the correct Qt flags into the project, the destination folder was common to both versions probably mixing some intermediate file (dll files were different).

I am not sure 100% if this was the real cause, but if you face another problem similar to this one, try first using different destination directories.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文