on Sep 11th, 2006ruby-ldap and win32

ruby-ldap is a ruby module for communicating with LDAP, also know as ActiveDirectory for Windows. Unfortunately there is not a windows version of the module. I found a site that explained how to compile and get it working for windows, but it looks like the site is dead now, so I am going to go ahead and explain how I got it working.

Requirements

Step-by-Step

  1. Download the ruby-ldap source. Make sure you get the tar.gz file and decompress it to a temp dir.
  2. Goto C:\ruby\lib\ruby\1.8\i386-mswin32(or wherever you installed Ruby too) and open up the file "config.h" in your favorite text-editor. The first 3 lines should look like this:
    C++:
    1. #if _MSC_VER != 1200
    2.   #error MSC version unmatch
    3.   #endif

    Basically what these 3 lines are saying is that if the microsoft compiler is not equal to version 1200(some internal code), then raise an error. The 2005 compiler that we will be using is not version 1200, so to get ruby-ldap compiled we need to remove these 3 lines. Feel free to add them back afterwards.

  3. We now need to correctly setup our environment and environment variables. All I did to get this to work was to run "C:\Documents and Settings\All Users\Start Menu\Programs\Microsoft Platform SDK for Windows Server 2003 R2\Open Build Environment Window\Windows XP 32-bit Build Environment\Set Windows XP 32-bit Build Environment (Retail)". Running this should launch a cmd window. Navigate to the ruby-ldap source directory. I should mention that the previous article that is now gone that explained how to do this, had a couple more steps required on getting your environment setup correctly. This is all I did and it worked fine for me though.
  4. Execute the follow command from the window we launched in the last step.
    CODE:
    1. ruby extconf.rb --with-wldap32

  5. Run
    CODE:
    1. nmake

    You should now have a ldap.so file.

  6. Now we need to embed the manifest so the module will work.
    CODE:
    1. mt -outputresource:ldap.so;2 -manifest ldap.so.manifest

    The original article mentioned that you need to install the Microsoft Visual C++ 2005 Redistributable, but I didn't have to.

  7. Now it's time to create the gem. Create a ldap.gemspec file and paste this code into it:
    RUBY:
    1. Gem::Specification.new do |spec|
    2.   spec.authors = ["Takaaki Tateishi", "Ian Macdonald"]
    3.   spec.email = 'ian@caliban.org'
    4.   spec.name = 'ldap'
    5.   spec.summary = 'LDAP library for Ruby'
    6.   spec.description = <<-EOF
    7.     ldap is a Ruby library to perform queries on an LDAP server
    8.   EOF
    9.   spec.version = '0.9.7'
    10.   spec.autorequire = 'ldap'
    11.   spec.platform = Gem::Platform::WIN32
    12.   spec.files = Dir['lib/**/*.rb'] + Dir['lib/*.so']
    13.   spec.required_ruby_version = '>= 1.8.0'
    14.   spec.require_paths = ['lib']
    15. end

  8. Move the module into the lib directory so Ruby will find it.
    CODE:
    1. move ldap.so lib

  9. It's time to build the gem.
    CODE:
    1. gem build ldap.gemspec

  10. Install the gem.
    CODE:
    1. gem install ldap-x.y.z-mswin32.gem

That's is all. The original site I got most of this stuff from is here. It looks like he deleted all his old posts though. The Google cache of all his related articles are here, here, and here.

6 Responses to “ruby-ldap and win32”

  1. RubyRed : Ruby/LDAP 0.9.7 for Win32on 26 Sep 2006 at 4:19 pm

    […] Posted by Jan Szumiec Tue, 26 Sep 2006 16:18:49 GMT I’ve just built a rubygem of Ruby/LDAP 0.9.7 under Windows using the instructions from this blog entry. If anyone feels like he trusts my binaries, you can grab a copy of the gem below: […]

  2. Olivier Boudryon 04 Oct 2006 at 11:39 am

    Microsoft Visual C++ Redistributable is required as long as you don’t installed Visual C++ 2005 or any application built with that tool.

  3. Xavieron 17 Oct 2006 at 11:50 pm

    Very handy, I used these instructions to compile Mongrel.

  4. […] Ruby LDAP and Windows […]

  5. Anders Øyvind Sætreon 12 Feb 2007 at 11:35 am

    Yup, this article worked. I used the Visual Studio 2005 Command Prompt, though. Guess it is like Olivier Boudry said.

  6. David Rathmannon 26 Feb 2007 at 5:59 pm

    I just wanted to add that you can remove your dependency on msvcr80.dll by editing the makefile.

    Change line 40
    - CFLAGS = -MD -Zi -O2b2xg- -G6
    + CFLAGS = -MT -Zi -O2b2xg- -G6

    Then build. This also means that you do not have to embed the extra assembly in the manifest.

Trackback URI | Comments RSS

Leave a Reply