Unexpected undefined reference

我只是一个虾纸丫 提交于 2019-12-02 08:13:04

You're mixing C and C++ files. To make that work, you just have to tell the C++ compiler that it's calling a C function, by changing the header file like so:

#ifndef MOD_KBINPUT
#define MOD_KBINPUT
/* note I also fixed the macro so you aren't using a system-reserved name */

#if __cplusplus
/* this is the important part */
extern "C" {
#endif

int kbInit();
int kbWait();

int kbTest();

#if __cplusplus
}
#endif

#endif

Otherwise the C++ compiler assumes the function will be given a C++ internal name (which encodes all the type information in the signature, this is what lets the linker distinguish between overloaded functions) and then the linker doesn't find it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!