Search code examples
rubyrubygemsrake

Creating Windows executable for ruby APP


I have written small script project on windows, I have three gems in my gem file

I am using Travelling ruby on ubuntu to create its package but in the rake task when script try to dowload the gems these three gems gives error because I think its window specific gems and look for some dependencies

I kept these gems with in the project and referenced in gem file , The script created zip file well, but when I run that on windows the errors that the win32... gems not found

    rake package:win32 outputs when it try to fetch gems 

```shell
Fetching gem metadata from http://rubygems.org/............
Fetching version metadata from http://rubygems.org/.
Resolving dependencies...
Using jmespath 1.3.1
Using ffi 1.9.14
Using mini_magick 4.3.6
Installing win32-api 1.4.8 (was 1.6.0) with native extensions
Using bundler 1.13.5
Using aws-sdk-core 2.6.10
Using rautomation 0.17.0
Using win32-clipboard 0.6.4
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /home/vishalgarg/.rvm/rubies/ruby-2.1.5/bin/ruby -r ./siteconf20161019-3963-1e9bkxl.rb extconf.rb
checking for strncpy_s()... no
creating Makefile

make "DESTDIR=" clean

make "DESTDIR="
compiling win32/api.c
win32/api.c:2:21: fatal error: windows.h: No such file or directory
 #include <windows.h>
                     ^
compilation terminated.
make: *** [api.o] Error 1

make failed, exit code 2


```

Solution

  • So Finally I got the answer, So Travelling ruby does't work for me because some of its limitations

    So its good to go with Ocra Gem (https://github.com/larsch/ocra)

    Simple install the gem on windows (I have made app on window) and run the command

    ocra <Ruby file name > --verbose --gem-full --no-dep-run --add-all-core --gemfile Gemfile
    

    It will generate the exe file and you are ready to run it on any windows