My steps:
1) Downloaded libgd from their download page:
http://www.libgd.org/releases/
(http://www.libgd.org/releases/gd-latest-win32.zip)
2) Extracted GD2 into it's own folder C:\GD2
3) Added the bin directory to the PATH
SET PATH=C:\GD2\bin;%PATH%
4) Installed gd2 gem:
C:\Users\Luis>gem install gd2
Fetching: gd2-1.1.1.gem (100%)
Successfully installed gd2-1.1.1
1 gem installed
5) Attempt to use gd2 from IRB:
C:\Users\Luis>irb
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'gd2'
RuntimeError: unknown error
from C:/Users/Luis/.gem/ruby/x86-mingw32/1.8/gems/gd2-1.1.1/lib/gd2.rb:58:in
`initialize'
from C:/Users/Luis/.gem/ruby/x86-mingw32/1.8/gems/gd2-1.1.1/lib/gd2.rb:58:in
`dlopen'
from C:/Users/Luis/.gem/ruby/x86-mingw32/1.8/gems/gd2-1.1.1/lib/gd2.rb:58
from C:/Users/Luis/Tools/Ruby/ruby-1.8.7-p330-i386-mingw32/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:34:in
`gem_original_require'
from C:/Users/Luis/Tools/Ruby/ruby-1.8.7-p330-i386-mingw32/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:34:in
`require'
from (irb):2
6) Hmn, error...
Let's see why:
gd2.rb, at line 58:
LIB = DL.dlopen(gd_library_name)
So is trying to load by DL the gd_library_name, let's look at
gd_library_name value is:
line 29,
def self.gd_library_name
case Config::CONFIG['arch']
when /darwin/
'libgd.2.dylib'
when /mswin32/, /cygwin/
'bgd.dll'
else
'libgd.so.2'
end
end
It is using arch to determine the OS, checking our Ruby values.
C:\Users\Luis>ruby -rrbconfig -ve "puts RbConfig::CONFIG['arch']"
ruby 1.8.7 (2010-12-23 patchlevel 330) [i386-mingw32]
i386-mingw32
Seems our mingw is not covered... let's do some small changes:
def self.gd_library_name
case RbConfig::CONFIG['host_os']
when /darwin/
'libgd.2.dylib'
when /mingw|mswin/, /cygwin/
'bgd.dll'
else
'libgd.so.2'
end
end
And trying again:
irb(main):002:0> require 'gd2'
RuntimeError: unknown symbol "gdFontCacheSetupA"
Better!, now let's see why we get unknown symbol, which lead me to
name_for_symbol, which requires similar platform changes...
But the problem is that name_for_symbol is not considering the calling
mode (stdcall versus cdecl)
Dunno if DL::Handle[] supports specifying the calling convention, but
for sure the gd2 library needs to be updated to consider mingw
platform, which seems the first blocker.
A possible replacement of gd2 gem will be gd2-ffij:
https://github.com/dark-panda/gd2-ffij
But suffers from the same mingw platform configuration issues, yet
still adding the calling convention sounds more easy.
I would suggest contact the gem Author about calling convention
methods as the library do not support them.
--
Luis Lavena
AREA 17
-
Perfection in design is achieved not when there is nothing more to add,
but rather when there is nothing more to take away.
Antoine de Saint-Exupéry
As mentioned before, I can't change every single library to make it
work. RubyInstaller shifted from mswin to mingw, but the calling
convention should be the same.
Now is up to the gem author fix that.
Even if we modify, is up to the gem author to provide a new release.
Forking is great for development, but gem forking is bad for
community.
Can't help you beyond the help already provided. Is up to you know
understand what the gem is doing.
(and is a good practice too, since using libraries without digging
into them may lead to weird results unknown to you)