问题
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 exactly sure how to go about doing this.
So far I can compile a Ruby C Extensions using extconf.rb and nmake from the Visual Studio Command Prompt more or less by following these instructions
http://blogs.law.harvard.edu/hoanga/2006/12/14/getting-a-ruby-c-extension-to-compile-on-windows/
However my Extension links libcurl, there is a line in extconf.rb to check for this
# Make sure the cURL library is installed.
have_library("curl")
When creating the makefile, I get
checking for main() in curl.lib... no
creating Makefile
and when running nmake, I get
fatal error C1083: Cannot open include file: 'curl/curl.h': No such file or directory
This is all expected, since its not installed. I have downloaded curl-7.26.0-devel-mingw64 (I think this is appropriate for Windows 7)
I just cant figure out in the Windows environment where I should put either /bin or /include so that my compiler can find them.
回答1:
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
来源:https://stackoverflow.com/questions/11480430/how-to-compile-a-ruby-c-extension-and-link-libcurl-on-windows