[Win32utils-devel] Trying to get RubyInline to work with VS
Heesob Park
phasis at gmail.com
Fri Jun 22 02:27:01 UTC 2012
Hi,
2012/6/22 Daniel Berger <djberg96 at gmail.com>
> Hi,
>
> I noticed that RubyInline did not work with Visual Studio (or mingw
> for that matter). I forked RubyInline and made some patches that look
> like they ought to work. Mostly it was just adjusting the build
> command string so that linker options came after the -link option,
> though I also changed the default extension to .dll and I make a
> Dir.chdir call before the build happens so that it doesn't build in
> the current directory.
>
> https://github.com/djberg96/rubyinline
>
> However, even after my patches I'm still having trouble. It builds,
> but it won't load. I tried it with this simple bit of inline code:
>
> # factorial.rb
> require "inline"
> class MyTest
> inline do |builder|
> builder.c "
> long factorial(int max) {
> int i=max, result=1;
> while (i >= 2) { result *= i--; }
> return result;
> }"
> end
> end
>
> t = MyTest.new()
> p t.factorial(5)
>
> I can see that it generated the .c code and built the .dll file in
> c:\Users\djberge\.ruby_inline\ruby-1.9.1
>
> Inline_MyTest_cb89593d1f9fe3ecdb2178215eee80ae.c
> Inline_MyTest_cb89593d1f9fe3ecdb2178215eee80ae.dll
>
> However, it fails trying to load the file:
>
> c:/usr/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
> `require': cannot load such file --
>
> C:/Users/djberge/.ruby_inline/ruby-1.9.1/Inline_MyTest_cb89593d1f9fe3ecdb2178215eee80ae.dll
> (LoadError)
> from
> c:/usr/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
> `require'
> from
> c:/usr/lib/ruby/gems/1.9.1/gems/RubyInline-3.11.2/lib/inline.rb:522:in
> `load'
> from
> c:/usr/lib/ruby/gems/1.9.1/gems/RubyInline-3.11.2/lib/inline.rb:859:in
> `inline'
> from factorial.rb:3:in `<class:MyTest>'
> from factorial.rb:2:in `<main>'
>
> What have I done wrong?
>
>
Ruby wants not .dll but .so for the extension name.
Here is a patch for your forked Rubyinline.
diff --git a/inline.rb b/inline.rb.new
index 3ac2f41..de45ee1 100644
--- a/inline.rb
+++ b/inline.rb.new
@@ -377,11 +377,7 @@ module Inline
def so_name
unless defined? @so_name then
- if WINDOZE
- @so_name = "#{Inline.directory}/#{module_name}.dll"
- else
@so_name =
"#{Inline.directory}/#{module_name}.#{RbConfig::CONFIG["DLEXT"]}"
- end
end
@so_name
end
@@ -571,7 +567,7 @@ VALUE #{method}_equals(VALUE value) {
nil
end
- if WINDOZE
+ if WINDOZE && RUBY_PLATFORM =~ /mswin/
cmd = [ RbConfig::CONFIG['LDSHARED'],
flags,
RbConfig::CONFIG['CFLAGS'],
@@ -657,7 +653,7 @@ VALUE #{method}_equals(VALUE value) {
# gawd windoze land sucks
case RUBY_PLATFORM
when /mswin32/ then
- " -link /LIBPATH:\"#{RbConfig::CONFIG['libdir']}\"
/DEFAULTLIB:\"#{RbConfig::CONFIG['LIBRUBY']}\" /INCREMENTAL:no
/EXPORT:Init_#{module_name}"
+ " -link /OUT:\"#{self.so_name}\"
/LIBPATH:\"#{RbConfig::CONFIG['libdir']}\"
/DEFAULTLIB:\"#{RbConfig::CONFIG['LIBRUBY']}\" /INCREMENTAL:no
/EXPORT:Init_#{module_name}"
when /mingw32/ then
c = RbConfig::CONFIG
" -Wl,--enable-auto-import -L#{c['libdir']}
-l#{c['RUBY_SO_NAME']}"
Regards,
Park Heesob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/win32utils-devel/attachments/20120622/1853edb4/attachment-0001.html>
More information about the win32utils-devel
mailing list