What format of .so is valid?

I created a .so on Linux and tried to load it in my plugin like this:

lib = Fiddle.dlopen(File.join(dir, "libfoo.so"))

But I got this error:

Fiddle::DLError: Exec format error

Then I tried to require it as:

require "libfoo"

Got another error:

LoadError: 193: %1 is not a valid Win32 application. 

How can I make a valid .so?

Go to the downloadable Books section of my Ruby Learning Resources topic thread and get the book about Extending Ruby with C.

Ignoring cross-compiling, you would need to compile your *.so file on Windows and/or macOS.

On Windows, you could compile it with Visual Studio msvc, or it might work compiling with MSYS2 ucrt.

Note that the main Ruby dll naming is not normal, as it matches a Ruby MSYS2 MINGW64 build.

If you’re interested, I think I have a Ruby 2.7 ucrt build on GitHub that matches the dll naming…

.so and .bundle in the Ruby world for Windows and Mac doesn’t match the names really used by the operating systems. If they did they’d be .dll and .dylib.

For examples on building Ruby C Extensions for SketchUp, refer to this repository: GitHub - SketchUp/ruby-c-extension-examples: Ruby C extension examples