How to Compile a Ruby C Extension and link libcurl on Windows

前端 未结 1 1845
故里飘歌
故里飘歌 2020-12-17 05:28

I am trying to build a Ruby C Extensions that uses libcurl. So far I have built it sucessfully on Os X. However I am much less experienced developing in Windows and am not e

相关标签:
1条回答
  • 2020-12-17 06:15

    On Windows you can have different compilers, from Visual Studio provided by Microsoft, GCC from MinGW project or Intel compiler.

    RubyInstaller (which I presume is the version of Ruby you're using) uses GCC (that is why it generates files with mingw in the name)

    Due the way Ruby works, you can't mix and match compilers. If Ruby was build with GCC, you need GCC to compile.

    Nowdays the recommended approach has been: RubyInstaller + DevKit. DevKit is a convenience package that provides all the tools required to compile Ruby C extensions.

    You can find all this plus installation instructions at RubyInstaller downloads page

    Once you have Ruby and DevKit installed, you can compile most of the extensions that do not depend on external libraries.

    Now, in your particular case, libcurl, RubyInstaller have provided some pre-compiled binaries that works perfectly to install curl-based tools.

    libcurl packages where announced at RubyInstaller group along other packages.

    You will need to download x86-windows package (link in the group page), instructions on how to extract and where to place it can be found in the same link. Please note that libcurl also needs c-ares, zlib and openssl packages.

    For example, to install curb gem, after I extracted the packages I just did:

    gem install curb -- --with-curl-dir=C:/Knapsack/x86-windows
    

    Where C:/Knapsack/x86-windows is the directory I extracted all the binary packages I mentioned before. I've also added the bin directory to my PATH so libcurl DLLs can be found and used.

    Note that while Windows uses \ to specify directory separator, you need to use / when providing the option to RubyGems.

    Note 2: In your post you mention downloaded mingw64, which most likely are 64bits binaries. Ruby is a 32bits executable so the packages I recommended are 32bits (x86). At this time RubyInstaller does not provide 64bits (x64) binaries.

    Hope this helps. If you have further questions on installing and using Ruby on Windows, please join RubyInstaller group

    0 讨论(0)
提交回复
热议问题