Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't link when used by a C++ project #15

Closed
jaryder opened this issue Mar 12, 2020 · 2 comments
Closed

Can't link when used by a C++ project #15

jaryder opened this issue Mar 12, 2020 · 2 comments

Comments

@jaryder
Copy link

jaryder commented Mar 12, 2020

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
@Frago9876543210
Copy link
Contributor

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() {}

@kubo kubo closed this as completed in 85e5523 Mar 15, 2020
@kubo
Copy link
Owner

kubo commented Mar 15, 2020

@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>
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants