发现一个符号和其他“未解析的外部符号”

时间:2012-04-16 21:14:03

标签: c visual-c++ linker visual-studio-2010

在我的Visual Studio 2010中有2个项目。一个是静态库(mhook 2.3,如果有人问),另一个是DLL。两者都设置为编译为/ MT。

mhook项目在mhook.h中有两个函数:

BOOL Mhook_SetHook(PVOID *ppSystemFunction, PVOID pHookFunction);
BOOL Mhook_Unhook(PVOID *ppHookedFunction);

dll项目引用mhook项目并使用Mhook_SetHook和Mhook_Unhook。使用相同的mhook.h。当我编译dll项目时,我收到以下错误:

1>hookdll.obj : error LNK2001: unresolved external symbol _Mhook_Unhook

注意,链接成功找到了Mhook_SetHook。如果我注释掉了Mhook_Unhook的使用,程序就会成功编译。

Dumpbin建议静态库中存在两个符号:

>dumpbin /symbols mhook-test.lib|find "Mhook"
015 00000000 SECT4  notype ()    External     | ?Mhook_SetHook@@YAHPAPAXPAX@Z (i
nt __cdecl Mhook_SetHook(void * *,void *))
122 00000000 SECT3B notype ()    External     | ?Mhook_Unhook@@YAHPAPAX@Z (int _
_cdecl Mhook_Unhook(void * *))
>

我迷茫和困惑,请帮助。

1 个答案:

答案 0 :(得分:1)

答案: 我显然混合了C ++和C代码 - 手头的库是C ++,我的程序是C.

我必须在它周围添加外部C,正如从Using C++ library in C code收集的那样:

#ifdef __cplusplus
extern "C" {
#endif
BOOL Mhook_SetHook(PVOID *ppSystemFunction, PVOID pHookFunction);
BOOL Mhook_Unhook(PVOID *ppHookedFunction);
#ifdef __cplusplus
} // extern "C"
#endif

一旦我完成了它,我的符号导出开始看起来好多了:

C:\Users\MACABRE\Documents\Visual Studio 2010\Projects\luahooker\Debug>dumpbin /
exports mhook.lib
Microsoft (R) COFF/PE Dumper Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file mhook.lib

File Type: LIBRARY

     Exports

       ordinal    name

                  _Mhook_SetHook
                  _Mhook_Unhook