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

Please add support for calling methods from C++ #554

Closed
Envek opened this issue Jan 17, 2017 · 1 comment
Closed

Please add support for calling methods from C++ #554

Envek opened this issue Jan 17, 2017 · 1 comment

Comments

@Envek
Copy link

Envek commented Jan 17, 2017

In #50 and #281 there said that Ruby FFI not currently supports C++ libraries with mangled method names.

Question: is it hard to add support for such C++ libraries?

So, If I have a library with custom.h with code like:

int scaleImg( unsigned char *BufImg, int &Maxx, int &Maxy, int Dpi );

and implementation like:

int scaleImg( unsigned char *BufImg, int &Maxx, int &Maxy, int Dpi ) {
    callCplusplusTemplatedFunction(param);
    doSomethingElse();
}

And I have compiled libcustom.dylib with this function, so nm -gU libcustom.dylib | grep scaleImg returns something like this:

0000000000046410 T __Z8scaleImgPhRiS0_i

And I would be happy if I could write something like this:

module Custom
  extend FFI::Library
  ffi_lib 'custom'
  attach_function 'scaleImg', '__Z8scaleImgPhRiS0_i', [:buffer_inout, :int, :int, :int], :int
end

And it will work.

If it's hard, can you add more detailed info to the README or wiki for how to make a C-style stub lib to call methods from C++-style .so or .dylib when I can't change this library (or it's hard as it heavily uses C++ stuff like templates and classes) and I have it's header files.

Thank you in advance.

@Envek
Copy link
Author

Envek commented Jan 18, 2017

Actually I was able to use mangled name (omitting first underscore from it):

attach_function :scaleImg, '_Z8scaleImgPhRiS0_i', [:buffer_inout, IntPtr, IntPtr, :int], :int

Thank you for FFI — it's awesome!

@Envek Envek closed this as completed Mar 18, 2017
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

1 participant