如何在Windows上编译Ruby的C扩展和链接的libcurl [英] How to Compile a Ruby C Extension and link libcurl on Windows

查看:182
本文介绍了如何在Windows上编译Ruby的C扩展和链接的libcurl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图构建一个使用libcurl的一个Ruby的C扩展。到目前为止,我已经成功建立了它在OS X但是我有经验要少得多在开发Windows,我不完全知道如何去这样做。

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.

到目前为止,我可以编译使用extconf.rb和NMAKE从Visual Studio命令一个Ruby的C扩展提示或多或少按照以下说明

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

<一个href=\"http://blogs.law.harvard.edu/hoanga/2006/12/14/getting-a-ruby-c-extension-to-compile-on-windows/\" rel=\"nofollow\">http://blogs.law.harvard.edu/hoanga/2006/12/14/getting-a-ruby-c-extension-to-compile-on-windows/

不过我扩展链接libcurl的,有在extconf.rb线检查此

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

和运行NMAKE时,我得到

and when running nmake, I get

fatal error C1083: Cannot open include file: 'curl/curl.h': No such file or directory

这是所有预期的,因为它的未安装。我已经下载卷曲7.26.0-DEVEL-mingw64(我认为这是适当的为Windows 7)

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)

我在Windows环境只是无法弄清楚,我应该把要么/ bin或/包括让自己的编译器可以找到它们。

I just cant figure out in the Windows environment where I should put either /bin or /include so that my compiler can find them.

推荐答案

在Windows中,可以有不同的编译器,从微软,从MinGW的项目或英特尔编译GCC提供的Visual Studio。

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

RubyInstaller(我presume是你正在使用Ruby的版本)使用GCC(这就是为什么它在名称中使用MinGW生成的文件)

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)

由于红宝石的工作方式,你不能混搭编译器。如果红宝石是建立与GCC,你需要GCC编译。

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

Nowdays推荐的方法是:RubyInstaller +的devkit。的devkit是一个方便的包,提供了所有Ruby编译C扩展所需的工具。

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

您可以在这里找到 RubyInstaller下载页面这一切再加上安装说明

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

如果你已经安装Ruby和的devkit,你可以编译大部分的扩展不依赖于外部库。

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

现在,你的具体情况,libcurl的,RubyInstaller提供了一些pre-编译的二进制文件的工作完全安装基于卷曲的工具。

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

在哪里沿着其他包 RubyInstaller组宣布的libcurl包。

libcurl packages where announced at RubyInstaller group along other packages.

您需要下载x86的窗户包(联系在组页),对如何提取和放置位置可以在同一链路中找到的指令。请注意,的libcurl也需要C-顷,zlib的和OpenSSL包。

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

其中, C:/背包/ x86的窗口是我提取所有我之前提到的二进制软件包的目录。我还添加了目录到我的 PATH 这样的libcurl的DLL可以被发现和使用。

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.

请注意,尽管Windows使用 \\ 来指定目录分隔符,你需要使用提供的选项时, / RubyGems的。

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

注2:在您的文章你提到下载mingw64,其中最有可能是64位二进制文​​件。 Ruby是一种32位的可执行文件,所以我推荐的包是32位(x86)的。这时RubyInstaller不提供64位(x64)的二进制文件。

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.

希望这有助于。如果您有关于Windows上安装和使用Ruby还有其他疑问,请加入 RubyInstaller组

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

这篇关于如何在Windows上编译Ruby的C扩展和链接的libcurl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆