错误LNK2005和C / C ++混合程序中的错误LNK2019

时间:2013-12-03 19:26:40

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

程序有:raw_mouse.h,raw_mouse.c RawInputRegistry.h RawInputRegistry.cpp和main.cpp

在raw_mouse.h中,

我定义了:

typedef WINUSERAPI INT (WINAPI *pGetRawInputDeviceList)(OUT PRAWINPUTDEVICELIST pRawInputDeviceList, IN OUT PINT puiNumDevices, IN UINT cbSize);

void testme();

在raw_mouse.c中我有:

_RRID = (pRegisterRawInputDevices)GetProcAddress(user32,"RegisterRawInputDevices");

void testme()
{
    int a =10;
}

我在raw_mouse.c中包含了raw_mouse.h,并在RawInputRegistry.h中包含了raw_mouse.h,最后在main.cpp中包含了RawInputRegistry.h

但是,我收到了这些错误:

RawInputRegistry.obj : error LNK2005: "int (__stdcall* _GRID)(struct HRAWINPUT__ *,unsigned int,void *,int *,unsigned int)" (?_GRID@@3P6GHPAUHRAWINPUT__@@IPAXPAHI@ZA) already defined in main.obj

RawInputRegistry.obj : error LNK2019: unresolved external symbol "void __cdecl testme(void)" (?testme@@YAXXZ) referenced in function "protected: __thiscall RawInputEventRegistry::RawInputEventRegistry(void)" (??0RawInputEventRegistry@@IAE@XZ)

不确定我是否应该使用extern“C”来包含raw_mouse.c中的所有代码?

1 个答案:

答案 0 :(得分:1)

  

不确定我是否使用extern“C”来包含raw_mouse.c中的所有代码?

来放s.th.将以下内容添加到您的raw_mouse.h文件中,以使其 #include同时兼容:

#ifndef RAW_MOUSE_H__
#define RAW_MOUSE_H__

#ifdef  __cplusplus
extern "C" {
#endif

/* Your C function declarations go here ... */

#ifdef  __cplusplus
}
#endif
#endif /* RAW_MOUSE_H__ */