Search code examples
crubywindowsmingw-w64

How to Obtain Ruby Library for C (MinGW-w64/Windows)


Currently, I am trying to run Ruby in a C program. However, I am at a complete loss on where to begin.

What I'm trying to accomplish is outlined in this really helpful guide: http://silverhammermba.github.io/emberb/embed/

However, it starts with using a gcc command that has -lruby within it. How may I obtain the Ruby library for compiling? (And specifically have it be for MinGW-w64).


I have tried using RubyInstaller (https://github.com/oneclick/rubyinstaller2), but still cannot find anyway to obtain a library.

I've also tried compiling the source from the Ruby Github (https://github.com/ruby/ruby), but once again, no luck.


Any detailed explanations for an idiot like me would be appreciated. ^^


Solution

  • I had the same problem recently and found 2 ways of obtaining the library:

    • When you get Ruby from RubyInstaller, you can find ruby.dll.a file (e.g. libx64-ucrt-ruby310.dll.a, depending on the version) in lib/ folder of your installation directory. You can use it for linking, but you'll need to also include all DLL files from bin/ (i.e. copy them next to the exe or whatever).
    • If you compile Ruby from source, you will get a .lib file that you can link (dynamically, or statically using -static one). It's probably a better option if you need to use a specific compiler.