Can't link when used by a C++ project
jaryder opened this issue · comments
Hi there, I was giving your API hook library a try and could not get linking to work (my project is using C++). After quite a bit of digging I found that the problem was C++ name mangling of the function declarations in funchook.h.
You can fix this by adding the following to explicitly use C-linkage conventions:
#ifdef __cplusplus
extern "C" {
#endif
... Your function declarations here ...
#ifdef __cplusplus
} // extern "C"
#endif
That sounds like asking for C++ API for this project. You can try to use something like that: https://github.com/minecraft-linux/server-modloader/tree/master/include/modloader
One drawback is long symbols names. I think it would be nice to find a way to simulate annotations in C++ to use that for hooking API.
For example rust has it:
#[hook(function address goes here)
fn some_hook() {}
#[hook(_ZN4Test3fooEv)
fn hook_by_symbol() {}
@jaryder Thanks for pointing. I fixed it as you requested.
As a workaround, could you include funchook.h as follows until the next release?
extern "C" {
#include <funchook.h>
}