Reputation: 2274
In my Visual Studio 2010 there are 2 projects. One is a static lib (mhook 2.3 if someone asks) and the other is a DLL. Both are set to compile as /MT.
mhook project has two functions in its mhook.h:
BOOL Mhook_SetHook(PVOID *ppSystemFunction, PVOID pHookFunction);
BOOL Mhook_Unhook(PVOID *ppHookedFunction);
the dll project references the mhook project and uses both Mhook_SetHook and Mhook_Unhook. Same mhook.h is used. When I compile the dll project, I get the following error:
1>hookdll.obj : error LNK2001: unresolved external symbol _Mhook_Unhook
Note, that the linked successfully found the Mhook_SetHook. If I comment out the use of Mhook_Unhook, the program compiles successfully.
Dumpbin suggests that both symbols are present in the static library:
>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 * *))
>
I am lost and confused, please help.
Upvotes: 1
Views: 577
Reputation: 2274
Answer: I was apparently mixing C++ and C code - the library at hand was in C++ and my program in C.
I had to add extern C around it, as gleaned from this 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
Once I had done it, my symbol exports started to look much better:
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
Upvotes: 1