Skip to content

How to compile ruby ldap on Windows

alexey-chebotar edited this page Oct 25, 2010 · 1 revision

How to compile ruby-ldap on Windows.

Requirements.

  • Ruby
    • In this article, uses RubyInstaller 1.9.2-p0 or 1.8.7-p302
  • mingw
    • In this article, uses RubyInstaller’s Development Kit 3.4.5r3 (20091110)
    • This provides gcc, make, and libraries.
  • Windows SDK or Microsoft Platform SDK
    • In this article, uses Windows SDK for Windows 7 and .NET Framework 4
    • This provides lib.exe

Patch your ruby environment

Notice! It’s a stop-gap solution.
I hope it’ll be solved by newer ruby and RubyInstaller.

for Ruby 1.9.2-p0

  • config.h
    --- include/ruby-1.9.1/i386-mingw32/ruby/config.h.old	Fri Aug 20 03:38:18 2010
    +++ include/ruby-1.9.1/i386-mingw32/ruby/config.h	Sat Sep 25 19:44:25 2010
    @@ -1,4 +1,5 @@
     /* confdefs.h */
    +#define HAVE_STRUCT_TIMEZONE
     #define CANONICALIZATION_FOR_MATHN 1
     #define STDC_HEADERS 1
     #define HAVE_SYS_TYPES_H 1
  • win32.h
    --- include/ruby-1.9.1/ruby/win32.h.old	Tue May 11 14:09:59 2010
    +++ include/ruby-1.9.1/ruby/win32.h	Sat Sep 25 14:55:42 2010
    @@ -266,7 +266,7 @@
     extern int rb_w32_uchown(const char *, int, int);
     extern int link(const char *, const char *);
     extern int rb_w32_ulink(const char *, const char *);
    -extern int gettimeofday(struct timeval *, struct timezone *);
    +// extern int gettimeofday(struct timeval *, struct timezone *);
     extern rb_pid_t waitpid (rb_pid_t, int *, int);
     extern rb_pid_t rb_w32_spawn(int, const char *, const char*);
     extern rb_pid_t rb_w32_aspawn(int, const char *, char *const *);
  • rbconfig.rb
    --- lib/ruby/1.9.1/i386-mingw32/rbconfig.rb.old	Fri Aug 20 03:48:20 2010
    +++ lib/ruby/1.9.1/i386-mingw32/rbconfig.rb	Sat Sep 25 19:40:05 2010
    @@ -59,7 +59,7 @@
       CONFIG["rubyw_install_name"] = "$(RUBYW_INSTALL_NAME)"
       CONFIG["LIBRUBY_DLDFLAGS"] = " -Wl,--enable-auto-image-base,--enable-auto-import -Wl,--out-implib=$(LIBRUBY) $(RUBYDEF)"
       CONFIG["LIBRUBY_LDSHARED"] = "$(CC) -shared $(if $(filter-out -g -g0,$(debugflags)),,-s)"
    -  CONFIG["warnflags"] = "-Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long"
    +  CONFIG["warnflags"] = "-Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-long-long"
       CONFIG["debugflags"] = "-g"
       CONFIG["optflags"] = "-O3"
       CONFIG["cxxflags"] = " $(optflags) $(debugflags) $(warnflags)"

Why need these patch?

  • I think, struct timezone problem cause by Ruby 1.9 - Bug #2587: Forced definition of struct timezone under MinGW - Ruby Issue Tracking System
  • The force definition of gettimeofday is another ruby’s problem.
  • rbconfig.rb’s compiler option problem caused by difference of compiler version of RubyInstaller and RubyInstaller’s Development Kit.
    • RubyInstaller’s Development Kit’s gcc is 3.4.5, and this version could not understand -Wno-missing-field-initializers.
    • The ruby.exe in RubyInstaller is compiled by newer gcc.

for Ruby 1.8.7-p302

  • win32.h
    --- lib/ruby/1.8/i386-mingw32/win32/win32.h.old	Tue Jun  8 18:39:56 2010
    +++ lib/ruby/1.8/i386-mingw32/win32/win32.h	Sun Oct  3 01:34:19 2010
    @@ -151,10 +151,7 @@
     #define unlink(p)		rb_w32_unlink(p)
     
     #ifdef __MINGW32__
    -struct timezone {
    -  int tz_minuteswest;
    -  int tz_dsttime;
    -};
    +struct timezone;
     #undef isascii
     #define isascii __isascii
     #endif
    @@ -204,7 +201,7 @@
     
     extern int chown(const char *, int, int);
     extern int link(char *, char *);
    -extern int gettimeofday(struct timeval *, struct timezone *);
    +// extern int gettimeofday(struct timeval *, struct timezone *);
     extern rb_pid_t waitpid (rb_pid_t, int *, int);
     extern int do_spawn(int, const char *);
     extern int do_aspawn(int, const char *, char **);

Why need these patch?

Execute commands on Command Prompt

"C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd"
git clone http://github.com/alexey-chebotar/ruby-ldap.git
cd ruby-ldap
ruby extconf.rb --with-wldap32
make
make install

Trouble Shooting

File truncated because make could not find ruby.exe

  • Problem
    gcc -shared -s -o ldap.so conn.o entry.o ldap.o misc.o mod.o saslconn.o sslconn.o -L. -LC:/ruby192/lib -L./win -L.  -Wl,--enable-auto-imagebase,--enable-auto-import ldap-i386-mingw32.def  -lmsvcrt-ruby191 -lwldap32  -lshell32 -lws2_32
    c:\Ruby192\devkit\gcc\3.4.5\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin\ld.exe: ldap-i386-mingw32.def:1: syntax error
    ldap-i386-mingw32.def: file not recognized: File truncated
    collect2: ld returned 1 exit status
    make: *** [ldap.so] Error 1
  • Solution
    For reasons not clearly understood, sometimes your ruby/bin path includes “zero sized and no exts” ruby file. (i.e. C:\Ruby192\bin\ruby)
    Therefore, make could not find true ruby file (i.e. C:\Ruby192\bin\ruby.exe)
    Please remove the fake ruby file then make will be able to find ruby.exe.
    After that, you also need to remove ldap-i386-mingw32.def or do make clean