Monday, July 5, 2010

Installing Curb with Ruby 1.9.1 in Windows

Disclaimer: This is about how I installed curb in Windows XP. This is probably not the only way and certainly not the best way. I'm not a Windows developer (I just play one on TV) and haven't done any work with C in an embarrassingly long time. I'll be happy to help with any problems, but please don't expect me to be able to fix this at 5pm on Friday when your production machine decides to blow up.

Now that we got that out of the way...

How I finally got curb to install in Windows.
  1. Install the latest Ruby installer and DevKit.
    The finer points of doing that are outside the scope of this post, so if you have trouble with those things I'd reccommend this tutorial, the DevKit Howto and the excellent RubyInstaller mailing list.

    Just for the record, I'm using the latest as of the time I'm writing this: ruby-1.9.1-p429 and devkit-3.4.5r3-20091110.7z.

  2. Get libcurl.
    I, again, am using the latest as of the time I'm writing this: 7.21.0. If you need a different version for whatever reason, the libcurl downloads page has a few different versions available, so make sure to get the one for mingw32 and that you get libcurl and not plain-old curl.

    With that downloaded, I extracted the .zip file to the root of my C:\ drive. The location you put this is important for the next steps.

  3. Put the curl binaries in your path.
    My preferred way is to add the libcurl \bin folder to the Windows path, so that typing 'path' at a Windows command prompt gives a result like this:

    C:\>path
    PATH=C:\Ruby191-p429\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\curl-7.21.0-devel-mingw32\bin;

    Other things you can do here are copy the libcurl .dll files into your ruby's \bin folder (or anywhere else in the PATH) but I think that's kinda lame.

  4. Install curb.
    The magic incantation I found for this was the following:

    gem install curb -- --with-curl-lib=C:\curl-7.21.0-devel-mingw32\bin --with-curl-include=C:\curl-7.21.0-devel-mingw32\include

    Every other combination of flags and paths resulted in compilation errors, so you've been warned. Also, you'll need to change the curl paths if you decided to install to a different place or with a different version.

  5. Test it.
    Here's a very simple script that will load curb and GET a url:
    require 'curb'

    c = Curl::Easy.new
    c.url = "http://example.com"
    c.http_get
    puts c.body_str.size

    # Output:
    # 574

Did this work for you? Let me know in the comments!

21 comments:

Unknown said...

Why do you specify --with-curl-lib=C:\curl-7.21.0-devel-mingw32\bin instead of --with-curl-lib=C:\curl-7.21.0-devel-mingw32\lib ?

What are the contents of both directories? For me, libcurl.a is in C:\curl-7.21.0-devel-mingw32\lib and the \bin directory contains only .dlls, which should not be useful for linking.

PyotrK said...

Thank you! It works.

PyotrK said...

I had already InstantRails installed and Ruby 1.8.6p111 with it. But curb gem had no wanted to be installed there. That's why I decided to follow your instructions :^).
I have use RubyInstaller 1.8.6-p398 from http://rubyinstaller.org/downloads/ and curb was installed successfully.
Many thanks once again

Anonymous said...

Great instructions, works perfect. Make sure you install the DevKit.

Thanks!

pete higgins said...

@ghazel: I did it that way simply because that was the only way I could get it to work. I haven't done any work in C in years, and the whys and hows of GCC are a little beyond me currently.

pete higgins said...

@ghazel: I forgot to mention, I'd actually prefer statically compiling the extension so that I didn't have to have the .dlls present at runtime, but like I said I couldn't figure it out.

Even with this doc page I'm a little too dense/lazy for it. If you have any luck getting it to work I'd definitely be interested in your solution.

alanisalan said...

Thanks a lot for the tutorials. The curl works like a charm.

What would happen if the devkit wasn't installed?

pete higgins said...

@alan k: The devkit includes make, gcc and other build tools required to compile C extensions. If the devkit was not installed the gem installation would not work.

alok said...

Works !! thanks a ton

send9 said...

Nice, this worked! Thanks!

Anonymous said...

Worked! Thanks a lot!

Anonymous said...

Had a real issue with the gem install command.

Every single time it would try to run it would give me invalid option. Finally got it to run with the following:

gem install curb --platform=ruby -- -- --with-curl-lib="C:/curl/bin" --with-curl-include="C:/curl/include"

It actually took two -- -- to make it finally realize the withs were for the ext build.

pak tani said...

thank bro, i'm very found this articel good job

Kannan said...

You are a STAR!. Works flawlessly

B.A. Walsh said...

It actually works! Thank you!

Kannan said...

Hi, recently I encountered an error when I tried to install feedzirra gem on windows/ruby 1.9.2. Here is what I got

.....
make
C:/Ruby192/bin/ruby -e "puts 'EXPORTS', 'Init_curb_core'" > curb_core-i386-mingw32.def
gcc -I. -IC:/Ruby192/include/ruby-1.9.1/i386-mingw32 -I/C/Ruby192/include/ruby-1.9.1/ruby/backward -I/C/Ruby192/include/ruby-1.9.1 -I. -DRUB
Y_EXTCONF_H=\"curb_config.h\" -IC:\curl-7.21.4-devel-mingw32\include -IC:\curl-7.21.4-devel-mingw32\bin/include -O3 -g -Wextra -Wno-unuse
d-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wall -o curb.o -c curb.c
In file included from curb.h:15:0,
from curb.c:8:
curb_easy.h:31:18: error: expected '{' before ';' token
curb_easy.h:31:9: error: two or more data types in declaration specifiers
make: *** [curb.o] Error 1


Gem files will remain installed in C:/Ruby192/lib/ruby/gems/1.9.1/gems/taf2-curb-0.5.4.0 for inspection.
Results logged to C:/Ruby192/lib/ruby/gems/1.9.1/gems/taf2-curb-0.5.4.0/ext/gem_make.out

Any help is appreciated. Thanks

pete higgins said...

Kannan,

Make sure you're installing the curb gem, not taf2-curb.

Kannan said...

Hi pete. Thanks for taking time to resolve my issue. Yes, I have installed curb but I need to use FeedZirra which says taf2-curb is required. Is there any way, I can not install taf2-curb yet use feedzirra or similar gems in windows?.

pete higgins said...

Kannan,

It looks like feedzirra removed their dependency on taf2-curb around two years ago. Are you trying to install an old version?

I'm sorry, I don't have any experience with taf2-curb or feedzirra, so if you continue to have problems I suggest asking on the rubyinstaller mailing list or filing an issue with feedzirra.

Kannan said...

Pete. Thanks for your help. This got resolved it by "gem install feedzirra :-). I have another problem, when I try to install curb in windows 7 (religiously following what I did with my xp machine), I get

"Error installing curb....checking for curl-config... no" and yes to the rest of checks. Any directions would be great.

JP said...

Worked really well for me. Here's the mirror where I got the version of curl he mentioned:

http://www.gknw.de/mirror/curl/win32/old_releases/