将 Qt 应用程序链接到 Google Breakpad 时出现未解析的符号错误

发布于 2024-10-08 14:08:09 字数 4294 浏览 8 评论 0原文

我试图将我的 Qt 应用程序静态链接到 Windows 下的 Google Breakpad,但我总是遇到未解决的符号错误。我正在使用 qmake 和 VC++2008,我的项目文件似乎有一些问题。看起来链接器是否忽略了我的 LIBS 规范,因为无论我是否将库添加到 LIBS,我都会收到错误。

我使用以下方法编译了 Breakpad:

vcbuild /platform:Win32

Google Breakpead 在 src\processor\test_app.cc 中包含一个示例。如果我按照建议编译它,一切都会顺利:

C:\test>cl /Zi test_app.cc /Fetest_app.exe /I C:\google-breakpad\src C:\google-breakpad\src\client\windows\Release\lib\exception_handler.lib C:\google-breakpad\src\client\windows\Release\lib\crash_generation_client.lib C:\google-breakpad\src\client\windows\Release\lib\common.lib

但是,如果我尝试使用类似的 .pro 文件使用 qmake 构建它,我会得到相同的未解决的符号错误。这是我使用的 .pro 文件:

TEMPLATE = app
TARGET = 
DEPENDPATH += .
INCLUDEPATH += .
INCLUDEPATH += C:/google-breakpad/src
SOURCES += test_app.cc

LIBS += C:/google-breakpad/src/client/windows/Release/lib/exception_handler.lib
LIBS += C:/google-breakpad/src/client/windows/Release/lib/crash_generation_client.lib
LIBS += C:/google-breakpad/src/client/windows/Release/lib/common.lib
PRE_TARGETDEPS += C:/google-breakpad/src/client/windows/Release/lib/exception_handler.lib
PRE_TARGETDEPS += C:/google-breakpad/src/client/windows/Release/lib/crash_generation_client.lib
PRE_TARGETDEPS += C:/google-breakpad/src/client/windows/Release/lib/common.lib

构建它:

C:\test>qmake -config release

C:\test>nmake

Microsoft (R) Program Maintenance Utility Version 9.00.21022.08
Copyright (C) Microsoft Corporation.  All rights reserved.

        "C:\Program files\Microsoft Visual Studio 9.0\VC\BIN\nmake.exe" -
f Makefile.Release

Microsoft (R) Program Maintenance Utility Version 9.00.21022.08
Copyright (C) Microsoft Corporation.  All rights reserved.

        cl -c -nologo -Zm200 -Zc:wchar_t- -O2 -MD -GR -EHsc -W3 -w34100 -w34189
-DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_NO_DEBUG -DQT_GUI_LIB -DQ
T_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAV
E_SSE2 -DQT_THREAD_SUPPORT -I"..\Qt\4.7.1\include\QtCore" -I"..\Qt\4.7.1\include
\QtGui" -I"..\Qt\4.7.1\include" -I"." -I"..\google-breakpad\src" -I"..\Qt\4.7.1\
include\ActiveQt" -I"release" -I"..\Qt\4.7.1\mkspecs\win32-msvc2008" -Forelease\
 @C:\Windows\Temp\nm94.tmp
test_app.cc
.\test_app.cc(43) : warning C4100: 'assertion' : unreferenced formal parameter
.\test_app.cc(42) : warning C4100: 'exinfo' : unreferenced formal parameter
.\test_app.cc(42) : warning C4100: 'context' : unreferenced formal parameter
.\test_app.cc(41) : warning C4100: 'dump_path' : unreferenced formal parameter
.\test_app.cc(62) : warning C4100: 'argv' : unreferenced formal parameter
.\test_app.cc(62) : warning C4100: 'argc' : unreferenced formal parameter
        link /LIBPATH:"c:\Qt\4.7.1\lib" /NOLOGO /INCREMENTAL:NO /MANIFEST /MANIF
ESTFILE:"release\test.intermediate.manifest" /SUBSYSTEM:WINDOWS "/MANIFESTDEPEND
ENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' pub
licKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /OUT:rele
ase\test.exe @C:\Windows\Temp\nm95.tmp
LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; us
e /NODEFAULTLIB:library
test_app.obj : error LNK2019: unresolved external symbol "public: __thiscall goo
gle_breakpad::ExceptionHandler::ExceptionHandler(class std::basic_string<unsigne
d short,struct std::char_traits<unsigned short>,class std::allocator<unsigned sh
ort> > const &,bool (__cdecl*)(void *,struct _EXCEPTION_POINTERS *,struct MDRawA
ssertionInfo *),bool (__cdecl*)(unsigned short const *,unsigned short const *,vo
id *,struct _EXCEPTION_POINTERS *,struct MDRawAssertionInfo *,bool),void *,int)"
 (??0ExceptionHandler@google_breakpad@@QAE@ABV?$basic_string@GU?$char_traits@G@s
td@@V?$allocator@G@2@@std@@P6A_NPAXPAU_EXCEPTION_POINTERS@@PAUMDRawAssertionInfo
@@@ZP6A_NPBG5123_N@Z1H@Z) referenced in function _main
release\test.exe : fatal error LNK1120: 1 unresolved externals
NMAKE : fatal error U1077: '"C:\Program files\Microsoft Visual Studio 9.0\VC\BIN
\link.EXE"' : return code '0x460'
Stop.
NMAKE : fatal error U1077: '"C:\Program files\Microsoft Visual Studio 9.0\VC\BIN
\nmake.exe"' : return code '0x2'
Stop.

.pro 文件中我缺少什么?

提前致谢。

I'm trying to statically link my Qt application to Google Breakpad under Windows but I always get unresolved symbol errors. I'm using qmake and VC++2008 and there seems to be some problem with my project file. It seems like if the linker was ignoring my LIBS specification because I get the error no matter I add the library to LIBS or not.

I compiled Breakpad using:

vcbuild /platform:Win32

Google Breakpead includes an example in src\processor\test_app.cc. If I compile it as suggested, everything goes fine:

C:\test>cl /Zi test_app.cc /Fetest_app.exe /I C:\google-breakpad\src C:\google-breakpad\src\client\windows\Release\lib\exception_handler.lib C:\google-breakpad\src\client\windows\Release\lib\crash_generation_client.lib C:\google-breakpad\src\client\windows\Release\lib\common.lib

However, if I try to build it with qmake using a similar .pro file I get the same unresolved symbol errors. This is the .pro file I use for it:

TEMPLATE = app
TARGET = 
DEPENDPATH += .
INCLUDEPATH += .
INCLUDEPATH += C:/google-breakpad/src
SOURCES += test_app.cc

LIBS += C:/google-breakpad/src/client/windows/Release/lib/exception_handler.lib
LIBS += C:/google-breakpad/src/client/windows/Release/lib/crash_generation_client.lib
LIBS += C:/google-breakpad/src/client/windows/Release/lib/common.lib
PRE_TARGETDEPS += C:/google-breakpad/src/client/windows/Release/lib/exception_handler.lib
PRE_TARGETDEPS += C:/google-breakpad/src/client/windows/Release/lib/crash_generation_client.lib
PRE_TARGETDEPS += C:/google-breakpad/src/client/windows/Release/lib/common.lib

Building it:

C:\test>qmake -config release

C:\test>nmake

Microsoft (R) Program Maintenance Utility Version 9.00.21022.08
Copyright (C) Microsoft Corporation.  All rights reserved.

        "C:\Program files\Microsoft Visual Studio 9.0\VC\BIN\nmake.exe" -
f Makefile.Release

Microsoft (R) Program Maintenance Utility Version 9.00.21022.08
Copyright (C) Microsoft Corporation.  All rights reserved.

        cl -c -nologo -Zm200 -Zc:wchar_t- -O2 -MD -GR -EHsc -W3 -w34100 -w34189
-DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_NO_DEBUG -DQT_GUI_LIB -DQ
T_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAV
E_SSE2 -DQT_THREAD_SUPPORT -I"..\Qt\4.7.1\include\QtCore" -I"..\Qt\4.7.1\include
\QtGui" -I"..\Qt\4.7.1\include" -I"." -I"..\google-breakpad\src" -I"..\Qt\4.7.1\
include\ActiveQt" -I"release" -I"..\Qt\4.7.1\mkspecs\win32-msvc2008" -Forelease\
 @C:\Windows\Temp\nm94.tmp
test_app.cc
.\test_app.cc(43) : warning C4100: 'assertion' : unreferenced formal parameter
.\test_app.cc(42) : warning C4100: 'exinfo' : unreferenced formal parameter
.\test_app.cc(42) : warning C4100: 'context' : unreferenced formal parameter
.\test_app.cc(41) : warning C4100: 'dump_path' : unreferenced formal parameter
.\test_app.cc(62) : warning C4100: 'argv' : unreferenced formal parameter
.\test_app.cc(62) : warning C4100: 'argc' : unreferenced formal parameter
        link /LIBPATH:"c:\Qt\4.7.1\lib" /NOLOGO /INCREMENTAL:NO /MANIFEST /MANIF
ESTFILE:"release\test.intermediate.manifest" /SUBSYSTEM:WINDOWS "/MANIFESTDEPEND
ENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' pub
licKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /OUT:rele
ase\test.exe @C:\Windows\Temp\nm95.tmp
LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; us
e /NODEFAULTLIB:library
test_app.obj : error LNK2019: unresolved external symbol "public: __thiscall goo
gle_breakpad::ExceptionHandler::ExceptionHandler(class std::basic_string<unsigne
d short,struct std::char_traits<unsigned short>,class std::allocator<unsigned sh
ort> > const &,bool (__cdecl*)(void *,struct _EXCEPTION_POINTERS *,struct MDRawA
ssertionInfo *),bool (__cdecl*)(unsigned short const *,unsigned short const *,vo
id *,struct _EXCEPTION_POINTERS *,struct MDRawAssertionInfo *,bool),void *,int)"
 (??0ExceptionHandler@google_breakpad@@QAE@ABV?$basic_string@GU?$char_traits@G@s
td@@V?$allocator@G@2@@std@@P6A_NPAXPAU_EXCEPTION_POINTERS@@PAUMDRawAssertionInfo
@@@ZP6A_NPBG5123_N@Z1H@Z) referenced in function _main
release\test.exe : fatal error LNK1120: 1 unresolved externals
NMAKE : fatal error U1077: '"C:\Program files\Microsoft Visual Studio 9.0\VC\BIN
\link.EXE"' : return code '0x460'
Stop.
NMAKE : fatal error U1077: '"C:\Program files\Microsoft Visual Studio 9.0\VC\BIN
\nmake.exe"' : return code '0x2'
Stop.

What am I missing in the .pro file?

Thanks in advance.

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

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

发布评论

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

评论(1

榕城若虚 2024-10-15 14:08:09

问题在于 Google Breakpad 库是在启用“Treat wchar_t asbuilt-in Type”(/Zc:wchar_t)的情况下编译的。 Qt 编译时禁用该选项 (/Zc:wchar_t-)。这意味着在编译时,一切都匹配:std::wstring 是根据unsigned Short 定义的,这正是 Qt 所期望的。但在链接时,Breakpad 库已根据 __wchar_t(或 wchar_t)定义了 wstring。结果是链接器无法解析您对其函数的调用,因为参数类型不匹配(在链接时)。

解决方案是:

  • 禁用“将 wchar_t 视为内置类型” " 在 Google Breakpad 库中(在配置属性 > C/C++ > 语言下。(这就是我们正在尝试的...)
  • 在 Qt 中启用该选项(删除 /Zc:wchar_t-

有关详细信息:

(这个很微妙;让我们难住了一天的大部分时间。)

The issue is that the Google Breakpad library is compiled with "Treat wchar_t as Built-in Type" enabled (/Zc:wchar_t). Qt compiles with that option disabled (/Zc:wchar_t-). This means that at compile time, everything matches up: the std::wstring is defined in terms of unsigned short, which is what Qt expects. But at link time, the Breakpad library has defined wstring in terms of __wchar_t (or wchar_t). The effect is that the linker cannot resolve your call to their function, since the parameter types to not match (at link time.)

The solution is to either:

  • disable the "Treat wchar_t as Built-in Type" in the Google Breakpad library (under Configuration Properties > C/C++ > Language. (This is what we are trying...)
  • enable the option in Qt (remove /Zc:wchar_t-)

For more information:

(This one is subtle; had us stumped for the greater part of a day.)

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