1

The problem was to access G-WAN C API from Ruby

so i tried to use FFI, but gwan doesn't have any library, when i tried to load the binary, it shows:

/home/asd/.gem/ruby/2.0.0/gems/ffi-1.9.0/lib/ffi/library.rb:123:in `block in ffi_lib': Could not open library '/home/asd/bin/gwan_linux32-bit/gwan': /home/asd/bin/gwan_linux32-bit/gwan: cannot dynamically load executable (LoadError)
    from /home/asd/.gem/ruby/2.0.0/gems/ffi-1.9.0/lib/ffi/library.rb:90:in `map'
    from /home/asd/.gem/ruby/2.0.0/gems/ffi-1.9.0/lib/ffi/library.rb:90:in `ffi_lib'
    from /home/asd/bin/gwan_linux32-bit/127.0.0.1_8081/#127.0.0.1/csp/test.rb:26:in `<module:MyLibrary>'
    from /home/asd/bin/gwan_linux32-bit/127.0.0.1_8081/#127.0.0.1/csp/test.rb:24:in `<main>'

because, obviously, it's not the library, it's the executable binary

at first i think that i should make an C-extension for Ruby to access G-WAN API, but to think of it, it would also fail if we have no .o to link (only .h provided), right?

so.. is it possible to make Ruby's FFI to load from .h instead from dll?

Kokizzu
  • 24,974
  • 37
  • 137
  • 233

1 Answers1

0

The G-WAN API is not available from a shared library: it is provided by the G-WAN executable.

To have Ruby benefit from the G-WAN API, here's no substitute to G-WAN integrating the Ruby runtime, like it was done for C#, Java or Scala.

Try to find the relevant information (code examples about how to call C from Ruby and Ruby from C, and how to pass data structures between C and Ruby) and drop us a line at gwan.ch.

Don't forget to check that those resources are thread-safe because G-WAN is a multithread application.

Gil
  • 3,279
  • 1
  • 15
  • 25
  • how to call C/C++ from Ruby: http://stackoverflow.com/questions/1542520/how-can-i-call-c-functions-from-within-ruby (building a C extension, or C++ extension using SWIG, use FFI, or use RubyInline) – Kokizzu Jul 25 '13 at 07:25
  • how to call Ruby from C/C++: http://stackoverflow.com/questions/626333/embedding-a-ruby-interpreter-in-a-c-app just normal code, as Ruby MRI was made using C – Kokizzu Jul 25 '13 at 07:26