Visual Studio 2015 中的 Qt 项目:“未解析的外部符号 wWinMain" [英] Qt project in Visual Studio 2015: "unresolved external symbol wWinMain"
问题描述
整个错误输出是:
LNK2019 unresolved external symbol wWinMain referenced in function "int __cdecl __scrt_common_main_seh(void)" (?__scrt_common_main_seh@@YAHXZ) kachna-tracker C:\dev\kachna-tracker\MSVCRT.lib(exe_wwinmain.obj)
这是一个从 Qt Creator 导入的项目,只有在我尝试构建 Release
版本时才会出现此错误,Debug
版本运行得很好.据我所知,除了使用库的调试版本(例如 qtmain.lib
/qtmaind.lib
),两者之间的链接器配置没有区别.Debug
和 Release
配置.
This is a project imported from Qt Creator, and this error only occurs when I try to build the Release
version, Debug
version runs just fine. As far as I can tell, besides using the debug versions of the libraries (e.g. qtmain.lib
/qtmaind.lib
), there is no difference in the linker configuration between the Debug
and Release
configurations.
我发现可以通过将子系统设置为 /SUBSYSTEM:CONSOLE
而不是 /SUBSYSTEM:WINDOWS
来修复此错误,这确实解决了问题,但是当我构建一个 GUI 应用程序时,一个永久打开的控制台窗口非常难看,而且可能只能解决症状而不是原因.
I've found that this error can be fixed by setting the SubSystem to /SUBSYSTEM:CONSOLE
instead of /SUBSYSTEM:WINDOWS
, and this indeed does fix the issue, but as I am building a GUI application, a permanently open console window is quite unsightly, and also probably only fixes the symptom rather than the cause.
如何修复这个错误?
推荐答案
TL;DR
要么:
- 在发布中禁用 Unicode
- 或者在 Release 中添加/entry:mainCRTStartup 链接器标志
qtmain 库为 Windows 上的 WinMain 函数提供了一个包装器,允许您定义跨平台的 main() 函数.但目前,qtmain 库不支持 wWinMain 函数(WinMain 入口点的 unicode 版本).
The qtmain library provides a wrapper around the WinMain function on Windows, to allow you to define a cross-platform main() function. But for now, the wWinMain function (the unicode version of the WinMain entry point) is not supported by the qtmain library.
也许您的 Debug 和 Release 版本之间的区别在于您在编译时启用了 Unicode 而不是在 Debug 中启用.
Maybe the difference between your Debug and Release builds is that you compile with Unicode enabled in Release and not in Debug.
如果要在启用 Unicode 的情况下进行编译,则不应链接 qtmain 库,而应定义 wWinMain 而不是普通的旧 main.
If you want to compile with Unicode enabled, you should not link with the qtmain library, and you should define wWinMain instead of plain old main.
或者,您可以添加/entry:mainCRTStartup 链接器标志,以保持您的漂亮和标准的主要功能.请参阅此链接了解更多信息,以及这个很棒的答案 有关入口点的详细信息.
Alternatively, you can add the /entry:mainCRTStartup linker flag in order to keep your beautiful and standard main function. See this link for more information, and this awesome answer for detailed information about entry points.
这篇关于Visual Studio 2015 中的 Qt 项目:“未解析的外部符号 wWinMain"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!