现象
项目中静态链接某个库,库中明明有代码生成的obj,但是死活链接不上。记录这次debug过程,挺有意思的。
理解错误信息
error LNK2019: 无法解析的外部符号 “public: __cdecl google_breakpad::ExceptionHandler::ExceptionHandler(class std::basic_string<unsigned short,struct std::char_traits,class std::allocator<
unsigned short> > const &,bool (__cdecl*)(void *,struct _EXCEPTION_POINTERS *,struct MDRawAssertionInfo ),bool (__cdecl)(unsigned short const *,unsigned short const *,void *,struct _EXCEPTION_POINTERS *,struct MDRaw
AssertionInfo *,bool),void *,int,enum _MINIDUMP_TYPE,unsigned short const *,struct google_breakpad::CustomClientInfo const *)” (??0ExceptionHandler@google_breakpad@@QEAA@AEBV?
b
a
s
i
c
s
t
r
i
n
g
@
G
U
?
basic_string@GU?
basicstring@GU?char_traits@G@std@@V?$al
locator@G@2@@std@@P6A_NPEAXPEAU_EXCEPTION_POINTERS@@PEAUMDRawAssertionInfo@@@ZP6A_NPEBG5123_N@Z1HW4_MINIDUMP_TYPE@@5PEBUCustomClientInfo@1@@Z)
- 问题出现在link阶段
- 找不到构造函数ExceptionHandler
- ExceptionHandler对应的符号为加粗部分
验证静态库中是否有函数符号表
导出静态库的符号表
dumpbin /LINKERMEMBER breakpad.lib > 1.txt
tips:其中dumpbin命令需要直接打开visual studio 中的x64 Native Tools Command Prompt for VS 2019即可拥有
结果是有,但是有些许的不一样。我生成出来的函数都是类似:
0ExceptionHandler@google_breakpad@@QEAA@AEBV?
b
a
s
i
c
s
t
r
i
n
g
@
W
U
?
basic_string@_WU?
basicstring@WU?char_traits@_W@std@@V?
a
l
l
o
c
a
t
o
r
@
W
@
2
@
@
s
t
d
@
@
P
6
A
N
P
E
A
X
P
E
A
U
E
X
C
E
P
T
I
O
N
P
O
I
N
T
E
R
S
@
@
P
E
A
U
M
D
R
a
w
A
s
s
e
r
t
i
o
n
I
n
f
o
@
@
@
Z
P
6
A
N
P
E
B
W
512
3
N
@
Z
1
H
@
Z
很
明
显
,
allocator@_W@2@@std@@P6A_NPEAXPEAU_EXCEPTION_POINTERS@@PEAUMDRawAssertionInfo@@@ZP6A_NPEB_W5123_N@Z1H@Z 很明显,
allocator@W@2@@std@@P6ANPEAXPEAUEXCEPTIONPOINTERS@@PEAUMDRawAssertionInfo@@@ZP6ANPEBW5123N@Z1H@Z很明显,char_traits前,生成的是@_WU?,而连接器找的是@GU?。
解决问题
在visual studtio中添加链接参数 /Zc:wchar_t- 。其中 /Zc是指强制,最后面的的“-”是表示取消设置。这个参数的意思可能是,不强制转换wchar_t,没验证,不太了解。