Friday, August 3, 2012

Invoking native C/C++ libs using ruby

So as a continuation of the last post http://orphanware.blogspot.com/2012/08/making-c-available-through-native-calls.html...here is what you have to do with ruby

install ffi. linux distros have packages.....so on ubuntu apt-get install ffi...

then here is the module code as well as sample script

module LibMylib
        extend FFI::Library
        ffi_lib "libmylib.so"
        attach_function :MYLIB_helloWorld, [], :void
end
then your script. make sure libmylib is replaced with whatever u named the module file above
require 'ffi'
require 'libmylib'

LibMylib.MYLIB_helloWorld()

No comments:

Post a Comment