How to add .so files to ruby ffi

Hey guys, I have a self defined so file that I have been trying to incorporate in a ruby plugin file for use in Sketchup.
Whenever i try to start Sketchup,it loads to a point then crashes.
Can someone offer any advice in this regard

Could you share some of the internals of your .so? Is it a ruby extension?

Use of libFFI with Ruby is done via the Fiddle library …

You kind of need to poke around the Fiddle docs and modules to see examples.
http://ruby-doc.org/stdlib-2.5.1/libdoc/fiddle/rdoc/Fiddle.html
http://ruby-doc.org/stdlib-2.5.1/libdoc/fiddle/rdoc/Fiddle/Importer.html

It can also help searching the web for examples posted in blogs, etc.

How much experience do you have with Ruby ? … and writing C extension for Ruby ?

If you have not much I recommend downloading the PDF book on extending Ruby with C.
You can find it in the Books list, at the bottom of the “Downloadable” section …

Also see the SketchUp Extensibility Team’s examples …

1 Like

thanks a lot

Some people might be able to help, but maybe some more info?

We’ve got a ruby file loading an so file, and it crashes. When you say ‘crashes’, not sure if you mean SketchUp (SU) crashes, or something else.

Is it crashing when you call into it, or on require?

Any error output in the SU Ruby console?

JFYI, normally, an so file can be loaded via require, and (on Windows) a .dll file would be accessed via ffi/fiddle…

whenever i try loading my .so file using ffi or fiddle, Sketchup (SU) crashes. I mean when I restart SU it just flickers accross the screen, then closes

What version of SketchUp ? What platform ? What version of Ruby did you compile for ?

Ok. You’ve got an .so file.

If you say you have an .so file, most people in Ruby world consider that to be a compiled Ruby extension, similar to the files in your ‘Tools\RubyStdLib\platform_specific’ folder. These can be required just like a normal .rb file. For more info on .so files, see

https://msp-greg.github.io/ruby_trunk/file.extension.html

So, one would not normally load/access an .so file from FFI/Fiddle. FFI/Fiddle are for .dll’s.

So, what Dan said, and additionally, some idea of what the .so file is for, or what’s communicating with what and in what direction. What’s it linked to/dependent on?