# Cross Compiling Ruby Extension

**URL:** <https://www.ruby-forum.com/t/cross-compiling-ruby-extension/72584>\
**Category:** Ruby\
**Created:** [October 18, 2006, 9:59am UTC](https://www.ruby-forum.com/t/cross-compiling-ruby-extension/72584 "2006-10-18T09:59:47Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![bct](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6a8cbe/32.png) [@bct](https://www.ruby-forum.com/u/bct)\
**Post date:** [October 18, 2006, 9:59am UTC](https://www.ruby-forum.com/t/cross-compiling-ruby-extension/72584/1 "2006-10-18T09:59:47Z")

</div>

Hello,

I’m attempting to cross compile a ruby extension for Windows from a  
Linux  
box.  
Im running Ubuntu 6.06, Ruby 1.8.5, and mingw gcc 3.4.4.

I attempted to follow Mauricio F.'s instructions  
[http://eigenclass.org/hiki.rb?cross+compiling+rcovrt#f01](http://eigenclass.org/hiki.rb?cross+compiling+rcovrt#f01)

The file compiled but it appears that it is still a Linux binary.  
json\_ext.so: ELF 32-bit LSB shared object, Intel 80386, version 1  
(SYSV),  
not stripped

Is there something that I may be missing?

Thank you,  
Brian T.

---

<div class="post-metadata">

**Author:** ![bct](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6a8cbe/32.png) [@bct](https://www.ruby-forum.com/u/bct)\
**Post date:** [October 18, 2006, 3:54pm UTC](https://www.ruby-forum.com/t/cross-compiling-ruby-extension/72584/2 "2006-10-18T15:54:25Z")

</div>

On 10/18/06, Brian T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m attempting to cross compile a ruby extension for Windows from a Linux  
> box.  
> Im running Ubuntu 6.06, Ruby 1.8.5, and mingw gcc 3.4.4.

I don’t recommend doing this if you want your extension to be  
compatible with the current Windows Ruby release.

-austin

---

<div class="post-metadata">

**Author:** ![bct](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6a8cbe/32.png) [@bct](https://www.ruby-forum.com/u/bct)\
**Post date:** [October 18, 2006, 7:46pm UTC](https://www.ruby-forum.com/t/cross-compiling-ruby-extension/72584/3 "2006-10-18T19:46:11Z")

</div>

On 10/18/06, Austin Z. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On 10/18/06, Brian T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > I’m attempting to cross compile a ruby extension for Windows from a  
> > Linux  
> > box.  
> > Im running Ubuntu 6.06, Ruby 1.8.5, and mingw gcc 3.4.4.
> 
> I don’t recommend doing this if you want your extension to be  
> compatible with the current Windows Ruby release.

Thanks for your reply. I’m at my wit’s end in compiling ruby extensions  
on  
Windows. Ruby 1.8.5 is compiled under VC 6, right?

Its too bad that is very difficult to compile extensions for Windows.

Do you mind if I pick your brain at the conference?

-austin

---

<div class="post-metadata">

**Author:** ![bct](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6a8cbe/32.png) [@bct](https://www.ruby-forum.com/u/bct)\
**Post date:** [October 18, 2006, 8:50pm UTC](https://www.ruby-forum.com/t/cross-compiling-ruby-extension/72584/4 "2006-10-18T20:50:51Z")

</div>

On 10/18/06, Brian T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Its too bad that is very difficult to compile extensions for Windows.
> 
> Do you mind if I pick your brain at the conference?

You can try – I’m going to be interested in picking a lot of peoples’  
brains at the conference about this issue. See a notice that I’ll be  
posting later tonight.

-austin

---

<div class="post-metadata">

**Author:** ![bct](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6a8cbe/32.png) [@bct](https://www.ruby-forum.com/u/bct)\
**Post date:** [October 18, 2006, 9:00pm UTC](https://www.ruby-forum.com/t/cross-compiling-ruby-extension/72584/5 "2006-10-18T21:00:53Z")

</div>

On Wed, Oct 18, 2006 at 10:52:55PM +0900, Austin Z. wrote:

> On 10/18/06, Brian T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > I’m attempting to cross compile a ruby extension for Windows from a Linux  
> > box.  
> > Im running Ubuntu 6.06, Ruby 1.8.5, and mingw gcc 3.4.4.
> 
> I don’t recommend doing this if you want your extension to be  
> compatible with the current Windows Ruby release.

Isn’t mingw supposed to be compatible with the MSVC (which the  
One Click Installer uses now instead of some newer VC++) builds?

Ara mentioned some incompatibility on ruby-core (a problem with isascii  
IIRC)  
but it had been solved in CVS for a while.

---

<div class="post-metadata">

**Author:** ![bct](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6a8cbe/32.png) [@bct](https://www.ruby-forum.com/u/bct)\
**Post date:** [October 18, 2006, 8:54pm UTC](https://www.ruby-forum.com/t/cross-compiling-ruby-extension/72584/6 "2006-10-18T20:54:52Z")

</div>

On Wed, Oct 18, 2006 at 04:58:53PM +0900, Brian T. wrote:

> json\_ext.so: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV),  
> not stripped

You are using mkrf instead of mkmf, so things work a bit differently.

$ cat extconf.rb  
require ‘rubygems’  
require ‘mkrf’

dir = File.dirname( **FILE** )  
Mkrf::Generator.new(‘json\_ext’, “#{dir}/\*.c”)  
$ cat \> extconf.rb  
require ‘mkmf’  
create\_makefile “json\_ext”  
$ ruby -I ~/usr/ruby-mingw32/lib/ruby/1.8/i386-mingw32 extconf.rb  
/home/batsman/ruby-mingw32/lib/ruby/1.8/i386-mingw32/rbconfig.rb:7: ruby  
lib version (1.8.4) doesn’t match executable version (1.8.5)  
(RuntimeError)  
from /home/batsman/usr//lib/ruby/1.8/mkmf.rb:4:in `require' from /home/batsman/usr//lib/ruby/1.8/mkmf.rb:4 from extconf.rb:1:in`require’  
from extconf.rb:1

[use vim to edit rbconfig.rb and remove/comment the version check if the  
native & cross-compiled ruby version differ]

$ ruby -I ~/ruby-mingw32/lib/ruby/1.8/i386-mingw32/ extconf.rb  
creating Makefile  
$ make  
i586-mingw32msvc-gcc -I.  
-I/home/batsman/ruby-mingw32/lib/ruby/1.8/i386-mingw32  
-I/home/batsman/ruby-mingw32/lib/ruby/1.8/i386-mingw32 -I. -g -O2 -c  
json\_ext.c  
i586-mingw32msvc-gcc -shared -s -Wl,–enable-auto-import,–export-all  
-L"/home/batsman/ruby-mingw32/lib" -o json\_ext.so json\_ext.o  
-lmsvcrt-ruby18 -lwsock32  
$ file json\_ext.so  
json\_ext.so: MS Windows PE 32-bit Intel 80386 console DLL

---

<div class="post-metadata">

**Author:** ![bct](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6a8cbe/32.png) [@bct](https://www.ruby-forum.com/u/bct)\
**Post date:** [October 19, 2006, 7:43am UTC](https://www.ruby-forum.com/t/cross-compiling-ruby-extension/72584/7 "2006-10-19T07:43:51Z")

</div>

On 10/18/06, Brian T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > 
> > 
> > $ cat extconf.rb  
> > lib version (1.8.4) doesn’t match executable version (1.8.5)  
> > creating Makefile
> 
> Thanks for demoing this. I’ll give it a shot.

It looks like the compile worked. I did not run make install on mingw.

There where a couple of issues with the install task, such as  
rubyw.exemissing and the .ext directory missing.  
To resolve this I copied ruby.exe to rubyw.exe and the ext directory to  
.ext

Thank you,  
Brian

–

---

<div class="post-metadata">

**Author:** ![bct](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6a8cbe/32.png) [@bct](https://www.ruby-forum.com/u/bct)\
**Post date:** [October 19, 2006, 7:47am UTC](https://www.ruby-forum.com/t/cross-compiling-ruby-extension/72584/8 "2006-10-19T07:47:51Z")

</div>

On 10/18/06, Austin Z. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Thanks for your reply. I’m at my wit’s end in compiling ruby extensions  
> > on  
> > Windows. Ruby 1.8.5 is compiled under VC 6, right?
> > 
> > Its too bad that is very difficult to compile extensions for Windows.
> > 
> > Do you mind if I pick your brain at the conference?
> 
> You can try – I’m going to be interested in picking a lot of peoples’  
> brains at the conference about this issue. See a notice that I’ll be  
> posting later tonight.

Yes. It would be good to look for a resolution to this issue at the  
conference. I cant wait to read your post.

-austin

---

<div class="post-metadata">

**Author:** ![bct](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6a8cbe/32.png) [@bct](https://www.ruby-forum.com/u/bct)\
**Post date:** [October 19, 2006, 4:02am UTC](https://www.ruby-forum.com/t/cross-compiling-ruby-extension/72584/9 "2006-10-19T04:02:04Z")

</div>

On 10/18/06, Mauricio F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > [eigenclass.org](http://eigenclass.org/hiki.rb?cross+compiling+rcovrt#f01)  
> > require ‘mkrf’  
> > from /home/batsman/usr//lib/ruby/1.8/mkmf.rb:4:in `require’  
> > i586-mingw32msvc-gcc -I.  
> > -I/home/batsman/ruby-mingw32/lib/ruby/1.8/i386-mingw32  
> > -I/home/batsman/ruby-mingw32/lib/ruby/1.8/i386-mingw32 -I. -g -O2 -c  
> > json\_ext.c  
> > i586-mingw32msvc-gcc -shared -s  
> > -Wl,–enable-auto-import,–export-all -L"/home/batsman/ruby-mingw32/lib" -o  
> > json\_ext.so json\_ext.o -lmsvcrt-ruby18 -lwsock32  
> > $ file json\_ext.so  
> > json\_ext.so: MS Windows PE 32-bit Intel 80386 console DLL

Thanks for demoing this. I’ll give it a shot.

–

> Mauricio F. - [http://eigenclass.org](http://eigenclass.org) - singular Ruby

On 10/18/06, **Mauricio F.** \<[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\> wrote:

> On Wed, Oct 18, 2006 at 04:58:53PM +0900, Brian T. wrote:  
> \>  
> Hello,  
> \>  
> \> I’m attempting to cross compile a ruby extension  
> for Windows from a Linux  
> \> box.  
> \> Im running Ubuntu 6.06,  
> Ruby 1.8.5  
> , and mingw gcc 3.4.4.  
> \>  
> \> I attempted to follow Mauricio  
> Fernandez’s instructions  
> \> [http://eigenclass.org/hiki.rb?cross+compiling+rcovrt#f01  
> ](http://eigenclass.org/hiki.rb?cross+compiling+rcovrt#f01)  
> \>  
> \> The file compiled but it appears that it is still a  
> Linux binary.  
> \> json\_ext.so: ELF 32-bit LSB shared object, Intel  
> 80386, version 1 (SYSV),  
> \> not stripped  
>   
> You are using mkrf  
> instead of mkmf, so things work a bit differently.  
>   
>   
> $ cat extconf.rb  
> require ‘rubygems’  
> require  
> ‘mkrf’  
>   
> dir =  
> File.dirname( **FILE** )  
> Mkrf::Generator.new(‘json\_ext’,  
> "#{dir}/\*.c")  
> $ cat \> extconf.rb  
> require  
> ‘mkmf’  
> create\_makefile "json\_ext"  
>   
> $ ruby -I ~/usr/ruby-mingw32/lib/ruby/1.8/i386-mingw32  
> extconf.rb  
> /home/batsman/ruby-mingw32/lib/ruby/1.8/i386-mingw32/rbconfig.rb:7:  
> ruby lib version (1.8.4) doesn’t match executable version (1.8.5)  
> (RuntimeError)  
>   
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from  
> /home/batsman/usr//lib/ruby/1.8/mkmf.rb:4:in  
> `require'<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /home/batsman/usr//lib/ruby/1.8/mkmf.rb:4<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from extconf.rb:1:in `require’  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from  
> extconf.rb:1  
>   
> [use vim to edit  
> rbconfig.rb and remove/comment the version check if the  
> native &  
> cross-compiled ruby version differ]  
>   
> $ ruby -I  
> ~/ruby-mingw32/lib/ruby/1.8/i386-mingw32/ extconf.rb  
> creating  
> Makefile  
> $ make  
> i586-mingw32msvc-gcc -I.  
> -I/home/batsman/ruby-mingw32/lib/ruby/1.8/i386-mingw32  
> -I/home/batsman/ruby-mingw32/lib/ruby/1.8/i386-mingw32 -I.&nbsp;&nbsp;-g  
> -O2&nbsp;&nbsp; -c json\_ext.c  
>   
> i586-mingw32msvc-gcc -shared -s  
> -Wl,–enable-auto-import,–export-all&nbsp;&nbsp;-L"/home/batsman/ruby-mingw32/lib"  
> -o json\_ext.so  
> json\_ext.o&nbsp;&nbsp;-lmsvcrt-ruby18&nbsp;&nbsp;-lwsock32  
> $ file  
> json\_ext.so  
> json\_ext.so: MS Windows PE 32-bit Intel 80386 console DLL

  
Thanks for demoing this. I'll give it a shot.   

  

> --  
> Mauricio F.&nbsp;&nbsp;-&nbsp;&nbsp; [http://eigenclass.org](http://eigenclass.org)&nbsp;&nbsp; -&nbsp;&nbsp;singular Ruby
