Closed Envek closed 7 years ago
This would allow you to bind to the hello function using ruby ffi
#include <iostream>
extern "C" void hello() {
std::cout << "hello" << '\n';
}
not really any other way - however you can probably use the mangled name if the library is pre-compiled. Each compiler mangles names in a different way
@stakach, thank you.
I was able to successfully use mangled name (omitting first underscore:
attach_function :scaleImg, '_Z8scaleImgPhRiS0_i', [:buffer_inout, IntPtr, IntPtr, :int], :int
Specifying extern "C"
before function declaration also helped. Previously I've tried to wrap whole custom.h
file to the extern "C" { }
block, but it broke everything (there were some linking errors at runtime).
May be dumb question, as I haven't work with C since university, but I can't figure it out.
In https://github.com/ffi/ffi/issues/281 it's advised to use ffi-compiler to create a stub lib and binding that using FFI.
So, I have some
custom.h
file somewhere in my system (probably installed from somelibcustom-dev
package) and I havelibcustom.so
somewhere in my system (probably installed from somelibcustom
package).In that
custom.h
contained next declaration:In corresponding
libcustom.so
it contained with C++ mangled name:Question: how to use ffi-compiler in such a case to be able to call
scaleImg
fromlibcustom.so
?Will it be enough to do something like this in, say,
example.cpp
:Thank you in advance.
Related issue: https://github.com/ffi/ffi/issues/554