RubyInLine, hello.rb, gcc, RbConfig::CONFIG['LDSHARED']

498 views
Skip to first unread message

jfacet

unread,
Apr 5, 2012, 5:16:21 AM4/5/12
to rubyin...@googlegroups.com
Hello,

I have installed ruby One-Click and DevKit with Windows 7.

I run C:\Ruby193\lib\ruby\gems\1.9.1\gems\RubyInline-3.11.2\demo\hello.rb

RubyInLine fails : "RubyInline-3.11.2/lib/inline.rb:594:in ``': No such file or directory - gcc -shared    -O3 -fno-omit-frame-pointer [etc.]"  
In RbConfig I read : "LDSHARED"=>"gcc -shared $(if $(filter-out -g -g0,-g),,-s)"

I don't find anything to help me from RubyInLine pages, and I am not very comfortable in english and system.
Please, what should I do ?

Luis Lavena

unread,
Apr 5, 2012, 3:13:31 PM4/5/12
to rubyin...@googlegroups.com
On Thu, Apr 5, 2012 at 6:16 AM, jfacet <jfa...@gmail.com> wrote:
> Hello,
>
> I have installed ruby One-Click and DevKit with Windows 7.
>

You mean "RubyInstaller" ?

> I run C:\Ruby193\lib\ruby\gems\1.9.1\gems\RubyInline-3.11.2\demo\hello.rb
>
> RubyInLine fails : "RubyInline-3.11.2/lib/inline.rb:594:in ``': No such file
> or directory - gcc -shared    -O3 -fno-omit-frame-pointer [etc.]"
> In RbConfig I read : "LDSHARED"=>"gcc -shared $(if $(filter-out -g
> -g0,-g),,-s)"
>
> I don't find anything to help me from RubyInLine pages, and I am not very
> comfortable in english and system.
> Please, what should I do ?
>

That is a known issue of RubyInline caused by non-expanded information
of RbConfig.

You can solve this by manually editing rbconfig.rb and change the
value of LDSHARED key.

Steps:

1) Locate rbconfig in your system.

In my case, I used "gem":

C:\Users\Luis>gem which rbconfig
C:/Users/Luis/Tools/Ruby/ruby-1.9.3-p155-i386-mingw32/lib/ruby/1.9.1/i386-mingw32/rbconfig.rb

2) Open that file in your editor.

3) Search for CONFIG["LDSHARED"] in the file (for Ruby 1.9.3 should be
around line 94)

4) Remove the non-expanded logic:

Change:

CONFIG["LDSHARED"] = "$(CC) -shared $(if $(filter-out -g
-g0,$(debugflags)),,-s)"

To:

CONFIG["LDSHARED"] = "$(CC) -shared "

(please note the space before the double quotes)

5) Save the file

6) Try RubyInline again.

Hope that helps.
--
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

jfacet

unread,
Apr 6, 2012, 9:57:58 AM4/6/12
to rubyin...@googlegroups.com
Thank you, I see with some help there is a solution. Yes, sorry, I use RubyInstaller.

I didn't find C:\Ruby193\lib\ruby\1.9.1\i386-mingw32\rbconfig.rb between  psych.so and ripper.so for a long time !

I changed  as you recommand the value of LDSHARED key in rbconfig.rb, but I have still an errror in RubyInline-3.11.2\demo\hello.rb :

Before change CONFIG["LDSHARED"] = "$(CC) -shared $(if $(filter-out -g -g0,$(debugflags)),,-s)" 

C:/Ruby193/lib/ruby/gems/1.9.1/gems/RubyInline-3.11.2/lib/inline.rb:594:in ``': No such file or directory - gcc -shared    -O3 -fno-omit-frame-pointer -g -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Werror=pointer-arith -Werror=write-strings -Werror=declaration-after-statement -Werror=implicit-function-declaration -L.  -I C:/Ruby193/include/ruby-1.9.1 -I C:/Ruby193/include/ruby-1.9.1/i386-mingw32 -I C:/Ruby193/include -LC:/Ruby193/lib -o "C:/Users/Username/.ruby_inline/ruby-1.9.1/Inline_Hello_5d41402abc4b2a76b9719d911017c592.so" "C:/Users/Username/.ruby_inline/ruby-1.9.1/Inline_Hello_5d41402abc4b2a76b9719d911017c592.c"   -Wl,--enable-auto-import -LC:/Ruby193/lib -lmsvcrt-ruby191 (Errno::ENOENT)
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/RubyInline-3.11.2/lib/inline.rb:594:in `build'

After change CONFIG["LDSHARED"] = "$(CC) -shared "  

C:/Ruby193/lib/ruby/gems/1.9.1/gems/RubyInline-3.11.2/lib/inline.rb:594:in ``': No such file or directory - gcc -shared    -Wl,--enable-auto-image-base,--enable-auto-import    -O3 -fno-omit-frame-pointer -g -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Werror=pointer-arith -Werror=write-strings -Werror=declaration-after-statement -Werror=implicit-function-declaration -L.  -I C:/Ruby193/include/ruby-1.9.1 -I C:/Ruby193/include/ruby-1.9.1/i386-mingw32 -I C:/Ruby193/include -LC:/Ruby193/lib -o "C:/Users/Username/.ruby_inline/ruby-1.9.1/Inline_Hello_5d41402abc4b2a76b9719d911017c592.so" "C:/Users/Username/.ruby_inline/ruby-1.9.1/Inline_Hello_5d41402abc4b2a76b9719d911017c592.c"   -Wl,--enable-auto-import -LC:/Ruby193/lib -lmsvcrt-ruby191 (Errno::ENOENT)
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/RubyInline-3.11.2/lib/inline.rb:594:in `build'

Do you think it fails because I do not have the file C:/Ruby193/lib -lmsvcrt-ruby191
(I have the file C:\Ruby193\lib\libmsvcrt-ruby191.dll.a)

Thank you for your help.

==============================================

Luis Lavena

unread,
Apr 6, 2012, 10:04:13 AM4/6/12
to rubyin...@googlegroups.com
On Fri, Apr 6, 2012 at 10:57 AM, jfacet <jfa...@gmail.com> wrote:
> Thank you, I see with some help there is a solution. Yes, sorry, I use
> RubyInstaller.
>
> I didn't find C:\Ruby193\lib\ruby\1.9.1\i386-mingw32\rbconfig.rb between
>  psych.so and ripper.so for a long time !
>

I don't understand what you say here, but I guess since you changed
LDSHARED in rbconfig.rb (bellow) you found the file.

That is incorrect.

The file libmsvcrt-ruby191.dll.a will be used by GCC when
-lmsvcrt-ruby191 is issued.

LD (the linker) will try to find lib<name>.dll.a and then lib<name>.a
libraries for the <name> you supplied to the -l parameter.

The problem you're getting is other: not finding GCC.

Have you invoked "devkitvars.bat" before attempting to compile?

By default DevKit will only be triggered during gem installation and
normally is not in the PATH, even if you decided to add Ruby to the
PATH.

"devkitvars.bat" is inside the DevKit directory, try calling it before, example:

C:\Users\Luis>C:\DevKit\devkitvars.bat
...

[now try RubyInline example again]

jfacet

unread,
Apr 6, 2012, 2:31:01 PM4/6/12
to rubyin...@googlegroups.com
You are perfectly right : 
In command line it works. 

C:\Users\Alpha>C:\DevKit\devkitvars.bat
Adding the DevKit to PATH...
C:\Users\Alpha>C:\Ruby193\lib\ruby\gems\1.9.1\gems\RubyInline-3.11.2\demo\hello.rb
hello world

But when I change the ruby program or its directory, it doesn't work in most cases.

Is there a way to indicate the path.
Many thanks.


=============== 

Le jeudi 5 avril 2012 11:16:21 UTC+2, jfacet a écrit :
Le jeudi 5 avril 2012 11:16:21 UTC+2, jfacet a écrit :
Le jeudi 5 avril 2012 11:16:21 UTC+2, jfacet a écrit :

Luis Lavena

unread,
Apr 6, 2012, 2:43:34 PM4/6/12
to rubyin...@googlegroups.com

The devkitvars.bat should work from any place.

Please copy the example code outside the gem and use "ruby demo.rb".

Sorry for top posting. Sent from mobile.

--
You received this message because you are subscribed to the Google Groups "RubyInstaller" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyinstaller/-/BRB2y8prdAgJ.
To post to this group, send email to rubyin...@googlegroups.com.
To unsubscribe from this group, send email to rubyinstalle...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyinstaller?hl=en.

Luis Lavena

unread,
Apr 6, 2012, 2:44:34 PM4/6/12
to rubyin...@googlegroups.com

Also, please provide the exact output you get when you say "does not work". With that we can help you better.

Sorry for top posting. Sent from mobile.

On Apr 6, 2012 3:31 PM, "jfacet" <jfa...@gmail.com> wrote:

jfacet

unread,
Apr 9, 2012, 1:01:12 PM4/9/12
to rubyin...@googlegroups.com
Thank you,

I try to run the program "copie-hello.rb" in "Desktop/Test-RubyInLine".
This program is copied below between the hyphens lines : 
----------------------------------------
# coding: Windows-1252
$stdout.sync = true 
# super is Username

system 'cd'
print "*\n"

system 'path'  
print "**\n"

# suppress Inline_Hello1[...].c or .o if exists
system('del C:\Users\super\.ruby_inline\ruby-1.9.1\Inline_Hello1*.*') 

require 'inline'
print "*** \n"
class Hello1
  inline do |builder|
    builder.include "<stdio.h>"
    builder.c 'void hello1() { puts("hello = = = = world"); }'
  end
end

Hello1.new.hello1
-----------------------------------
In command line, after C:\DevKit\devkitvars.bat, the program  copie-hello.rb  works ok as below  between the hyphens lines :
-----------------------------------
Microsoft Windows [version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. Tous droits réservés.

C:\Users\super>cd C:\Users\super\Desktop\Test-RubyInLine

C:\Users\super\Desktop\Test-RubyInLine>C:\DevKit\devkitvars.bat
Adding the DevKit to PATH...

C:\Users\super\Desktop\Test-RubyInLine>path
PATH=C:\DevKit\bin;C:\DevKit\mingw\bin;C:\Program Files (x86)\ImageMagick-6.6.9-
Q16;           [ ... ]           C:\Ruby193\bin;C:\Ruby192\bin

C:\Users\super\Desktop\Test-RubyInLine>C:\Users\super\Desktop\Test-RubyInLine\co
pie-hello.rb
C:\Users\super\Desktop\Test-RubyInLine
*
PATH=C:\DevKit\bin;C:\DevKit\mingw\bin;C:\Program Files (x86)\ImageMagick-6.6.9-
Q16;           [ ... ]           C:\Ruby193\bin;C:\Ruby192\bin
**
***
hello = = = = world


C:\Users\super\Desktop\Test-RubyInLine>
-----------------------------------
[ ... ]  indicates suppressed lines (or suppressed caracters)
Two files are created in C:\Users\super\.ruby_inline\ruby-1.9.1 :
C:\Users\super\.ruby_inline\ruby-1.9.1\Inline_Hello1*.c and .so

When I open C:\Users\super\Desktop\Test-RubyInLine and I click on the name of the file C:\Users\super\Desktop\Test-RubyInLine\copie-hello.rb, execution start and fails.
When I run C:\Users\super\Desktop\Test-RubyInLine\copie-hello.rb from SciTE I get  : (below  between the hyphens lines)
-----------------------------------
>ruby copie-hello.rb
C:\Users\super\Desktop\Test-RubyInLine
*
PATH=C:\Program Files (x86)\ImageMagick-6.6.9-Q16;  [ ... ]  C:\Ruby193\bin;C:\Ruby192\bin
**
*** 
C:/Ruby193/lib/ruby/gems/1.9.1/gems/RubyInline-3.11.2/lib/inline.rb:594:in ``': No such file or directory - gcc -shared    -O3 -g -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Werror=pointer-arith -Werror=write-strings -Werror=declaration-after-statement -Werror=implicit-function-declaration -L.  -I C:/Ruby193/include/ruby-1.9.1 -I C:/Ruby193/include/ruby-1.9.1/i386-mingw32 -I C:/Ruby193/include -LC:/Ruby193/lib -o "C:/Users/super/.ruby_inline/ruby-1.9.1/Inline_Hello1_203ad5ffa1d7c650ad681fdff3965cd2.so" "C:/Users/super/.ruby_inline/ruby-1.9.1/Inline_Hello1_203ad5ffa1d7c650ad681fdff3965cd2.c"   -Wl,--enable-auto-import -LC:/Ruby193/lib -lmsvcrt-ruby191 (Errno::ENOENT)
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/RubyInline-3.11.2/lib/inline.rb:594:in `build'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/RubyInline-3.11.2/lib/inline.rb:830:in `inline'
from copie-hello.rb:17:in `<class:Hello1>'
from copie-hello.rb:16:in `<main>'
>Exit code: 1
------------------------------------
------------------------------------
Then I try an other program : "C:\Users\super\Desktop\Test-RubyInLine\test_path_DevKit.rb" below
-------------------------------------

$stdout.sync = true 
system 'cd'

system 'path' 
print "*\n"
system "C:/DevKit/devkitvars.bat"
print "**\n"
system 'path'  
print "***\n"

gets

--------------------------------------
And I get with SciTE :
---------------------------------------
>ruby test_path_DevKit.rb
C:\Users\super\Desktop\Test-RubyInLine
PATH=C:\Program Files (x86)\ImageMagick-6.6.9-Q16; [ ... ]  C:\Ruby193\bin;C:\Ruby192\bin
*
Adding the DevKit to PATH...
**
PATH=C:\Program Files (x86)\ImageMagick-6.6.9-Q16; [ ... ]  C:\Ruby193\bin;C:\Ruby192\bin
***

>Exit code: 0
-------------------------------------
Same result if I click on C:\Users\super\Desktop\Test-RubyInLine\test_path_DevKit.rb
To resume, C:\DevKit\bin;C:\DevKit\mingw\bin; is not in the path when execution of a Ruby program is launched by the system and is not added to the path (even if Adding the DevKit to PATH... is printed).

I hope what I say is easy to understand ... 

======================

Le jeudi 5 avril 2012 11:16:21 UTC+2, jfacet a écrit :

Luis Lavena

unread,
Apr 9, 2012, 1:39:40 PM4/9/12
to rubyin...@googlegroups.com
On Mon, Apr 9, 2012 at 2:01 PM, jfacet <jfa...@gmail.com> wrote:
> Thank you,
>

> -----------------------------------


> In command line, after C:\DevKit\devkitvars.bat, the program  copie-hello.rb
>  works ok as below  between the hyphens lines :
> -----------------------------------

>


> When I open C:\Users\super\Desktop\Test-RubyInLine and I click on the name
> of the file C:\Users\super\Desktop\Test-RubyInLine\copie-hello.rb, execution
> start and fails.

That will fail since double-clicking the .rb file will not load GCC in
the PATH, which is required by RubyInline to compile the extension
properly.

> When I run C:\Users\super\Desktop\Test-RubyInLine\copie-hello.rb from SciTE
> I get  : (below  between the hyphens lines)
> -----------------------------------
>>ruby copie-hello.rb
> C:\Users\super\Desktop\Test-RubyInLine
> *
> PATH=C:\Program Files (x86)\ImageMagick-6.6.9-Q16;  [ ... ]
>  C:\Ruby193\bin;C:\Ruby192\bin
> **
> ***
> C:/Ruby193/lib/ruby/gems/1.9.1/gems/RubyInline-3.11.2/lib/inline.rb:594:in
> ``': No such file or directory - gcc -shared    -O3 -g -Wextra
> -Wno-unused-parameter -Wno-parentheses -Wno-long-long
> -Wno-missing-field-initializers -Werror=pointer-arith -Werror=write-strings
> -Werror=declaration-after-statement -Werror=implicit-function-declaration
> -L.  -I C:/Ruby193/include/ruby-1.9.1 -I
> C:/Ruby193/include/ruby-1.9.1/i386-mingw32 -I C:/Ruby193/include
> -LC:/Ruby193/lib -o
> "C:/Users/super/.ruby_inline/ruby-1.9.1/Inline_Hello1_203ad5ffa1d7c650ad681fdff3965cd2.so"
> "C:/Users/super/.ruby_inline/ruby-1.9.1/Inline_Hello1_203ad5ffa1d7c650ad681fdff3965cd2.c"
>   -Wl,--enable-auto-import -LC:/Ruby193/lib -lmsvcrt-ruby191 (Errno::ENOENT)
> from

Same for SciTE, SciTE knows nothing about where GCC is or how to add
it to the PATH.

If you find it annoying that you can't double click the rb files or
use SciTE, you can require "devkit" on top of your script:

require "devkit"

That way, DevKit will be loaded without the need to run devkitvars.bat before.

But will make your script be somehow limited to RubyInstaller and
DevKit be present, so be warned about that.

jfacet

unread,
Apr 11, 2012, 2:40:52 PM4/11/12
to rubyin...@googlegroups.com

Thank you very much for your help and attention. Now I can breath. I was lost.

Parenthesis : How someone trying to use Ruby with Windows can guess the way is just to add "Require 'devkit'  ".
? or !


======================

Le jeudi 5 avril 2012 11:16:21 UTC+2, jfacet a écrit :

Luis Lavena

unread,
Apr 11, 2012, 3:36:12 PM4/11/12
to rubyin...@googlegroups.com
On Wed, Apr 11, 2012 at 3:40 PM, jfacet <jfa...@gmail.com> wrote:
>
> Thank you very much for your help and attention. Now I can breath. I was
> lost.
>
> Parenthesis : How someone trying to use Ruby with Windows can guess the way
> is just to add "Require 'devkit'  ".
> ? or !
>

That is a good question. Once devkit gets installed it install two
files, which are listed when doing `ruby dk.rb install`, one is used
by RubyGems and the other is devkit.rb

Perhaps we need to document it properly.

Jon

unread,
Apr 11, 2012, 5:08:09 PM4/11/12
to rubyin...@googlegroups.com
>> Parenthesis : How someone trying to use Ruby with Windows can guess the way
>> is just to add "Require 'devkit'  ".
>> ? or !
>>
>
> That is a good question. Once devkit gets installed it install two
> files, which are listed when doing `ruby dk.rb install`, one is used
> by RubyGems and the other is devkit.rb
>
> Perhaps we need to document it properly.

The existing DevKit documentation at
https://github.com/oneclick/rubyinstaller/wiki/Development-Kit
currently documents the files installed and typical usage scenarios.
The last bullet of "4. Run Installation Scripts" lists the files
installed. The "Hacky Developer Scenario" subsection of "Example
Native RubyGem Installations using the DevKit" shows how one might use
`-rdevkit`.

For the situation in which one doesn't read the documentation we've
taken the time to create, we can't do much about that other than
remind them to read our documentation when they run into problems.

However, I do think our current summary is too cryptic, especially for
newcomers. And it certainly does not mention `require devkit` usage
in script; it assumes you already know that if `-rdevkit` can be used
from the command line, `require devkit` can be used in a script.
That's a bad assumption on our part.

@jfaset what wording do you think would have been more understandable
and saved you time? BTW, please don't be uncomfortable with your
english, it is very understandable :)

Jon

jfacet

unread,
Apr 12, 2012, 6:49:00 AM4/12/12
to rubyin...@googlegroups.com
People who use Linux (or Ipad ?) are young and clever.
People who use Windows are many, they hardly now what is a command line and MS-DOS.
I don't know why Microsoft has given up Ruby (and Python) after some help.
I don't know why when I go to the bookstore specialised in Computers & Technology, Ruby books have been replaced by Python books in 2012.
When I write a ruby program it does not work. I don't how to debug it from the command line. I thought it was not possible. I use SciTE which print errors. Using SciTE is not so easy (coding characters, using gets). And I don't know where I can learn what -rdevkit means.
Perhaps a little place should be given for newcomers using Windows, with a little ruby script as exemple. There is no reason to think the one for which you gave me help is a good one.
Yet I have to know more about config.rb, ENV (Object class) , changing ENV["PATH"].
Thank you.


=========================


Le jeudi 5 avril 2012 11:16:21 UTC+2, jfacet a écrit :

Justin Baker

unread,
Apr 12, 2012, 1:08:04 PM4/12/12
to rubyin...@googlegroups.com
 On Thursday, April 12, 2012 5:49:00 AM UTC-5, jfacet wrote:
People who use Linux (or Ipad ?) are young and clever.
People who use Windows are many, they hardly now what is a command line and MS-DOS.
I don't know why Microsoft has given up Ruby (and Python) after some help.
I don't know why when I go to the bookstore specialised in Computers & Technology, Ruby books have been replaced by Python books in 2012.

I'm young and I use Windows! But in all honesty I get what you're saying, Microsoft almost frowns up dropping into the command line.

I think that is somewhat changing with the coming of Powershell but it's still not a common for Windows programmers to use Powershell.
But in the past few years of Sys-admin work and Programming, I've fallen in love with the command line. 

But it's really just a culture thing, and the Windows programming culture just isn't used to using command line tools.
 
When I write a ruby program it does not work. I don't how to debug it from the command line. I thought it was not possible. I use SciTE which print errors. Using SciTE is not so easy (coding characters, using gets). And I don't know where I can learn what -rdevkit means.

So basically I don't know how to use an editor like SciTE to Run or Debug a Ruby file. I can only use a command line prompt.
Using an editor to do command line work (like Visual Studio does) is actually pretty hard. I could never get it to work well.

You can learn what -rdevkit does by running 'ruby --help' in the command prompt. For simplicity the line that explains it is

  -rlibrary       require the library, before executing your script

I actually didn't know about this until I read this post. It's actually pretty cool.

Perhaps a little place should be given for newcomers using Windows, with a little ruby script as exemple. There is no reason to think the one for which you gave me help is a good one.

Most of the pure Ruby scripts work out of the box, and most of the popular seem to just work on Windows.

What you're doing (at least for me) is a very simple but interesting case that uses Ruby to write C code, that has to be
compiled by a C compiler, instead of interpreted by the Ruby interpreter. 
Basically Ruby has to depend on a outside executable in this situation. But, it assumes you already know where that
executable is. (this is what ENV["PATH"] is for)
 
Yet I have to know more about config.rb, ENV (Object class) , changing ENV["PATH"].
Thank you.

The ENV class is essentially just a wrapper around the Environment Variables for the current process.


However, I do think our current summary is too cryptic, especially for
newcomers.  And it certainly does not mention `require devkit` usage
in script; it assumes you already know that if `-rdevkit` can be used
from the command line, `require devkit` can be used in a script.
That's a bad assumption on our part.

@jfaset what wording do you think would have been more understandable
and saved you time?  BTW, please don't be uncomfortable with your
english, it is very understandable :)

@Jon How about something like,

  Alternatively you can load the devkit environment programmatically using 'require devkit'.

That being said, why doesn't operating_system.rb just use 'require devkit'?

Justin

Jon

unread,
Apr 12, 2012, 3:42:54 PM4/12/12
to rubyin...@googlegroups.com
> But it's really just a culture thing, and the Windows programming culture
> just isn't used to using command line tools.

While the command line culture comment is valid, part of the issue is the MRI Ruby project has historically done a poor job of promoting and supporting Ruby on Windows as a first class citizen.

Many newcomers find a wealth of *nix examples and blogs showing Ruby's quirks on Linux, et al, but not as many on Windows. Some Rubyists think they're being clever when they make degrading comments like "winbloze, windoze, etc". They fail to see that they're harming Ruby by ridiculing Ruby running on Windows. It's a bit like ridiculing your younger brother because he likes to wear cobalt blue and you like to wear red.

This really is a shame and can lead a newcomer to believe that Ruby on Windows just doesn't work. Nothing could be further from the truth as both this project and JRuby shows.

The fact is, it's Ruby we primarily care about rather than a specific OS. OS's do matter, but at the level we're talking about, we want a great Ruby experience regardless of which OS we're using.

As you get more experience with MRI on Windows you find that there is a _lot_ of Windows specifics in the core code. There's Windows specific code in RubyGems and many other widely used gems. There's very experienced committers on ruby-core that care about Windows-specific issues.

Rather than continue down this path, I'll leave it by simply saying this. Have patience, google and use the available documentation, learn how to best use RubyInstall + DevKit for a fun Ruby on Windows experience, and share your experiences to help other newcomers. Blog, tweet, enhance our wiki documentation, find ways to contribute, etc.


> However, I do think our current summary is too cryptic, especially for
> > newcomers. And it certainly does not mention `require devkit` usage
> > in script; it assumes you already know that if `-rdevkit` can be used
> > from the command line, `require devkit` can be used in a script.
> > That's a bad assumption on our part.
> >
> > @jfaset what wording do you think would have been more understandable
> > and saved you time? BTW, please don't be uncomfortable with your
> > english, it is very understandable :)
> >
> @Jon How about something like,
>
> Alternatively you can load the devkit environment programmatically using
> 'require devkit'.

Short and to the point :)

Please update the DevKit wiki page and we'll keep refining as needed. Make sure there's quote's around 'devkit'...`require "devkit"`.

> That being said, why doesn't operating_system.rb just use 'require devkit'?

The two files injected into your Ruby environment when you run `ruby dk.rb install` serve two different purposes.

operating_system.rb is a standardized way to enhance RubyGems (RG) behavior. It exists to automagically pull in the DevKit artifacts when you are installing a gem with native extensions. It's a convenience so that you don't have to remember special command line invocations when installing/updating.

Here's the operating_system.rb from one of my Rubies. Basically, it adds a pre_install hook to RG that tweaks PATH and other env vars only when installing/updating a gem with native extensions. A sublety is that the DevKit artifacts are available only for as long as they're needed to install/update a native gem and do not remain to pollute your PATH and potentially cause other problems.

# :DK-BEG: override 'gem install' to enable RubyInstaller DevKit usage
Gem.pre_install do |gem_installer|
unless gem_installer.spec.extensions.empty?
unless ENV['PATH'].include?('C:\\DevKit\\mingw\\bin') then
Gem.ui.say 'Temporarily enhancing PATH to include DevKit...' if Gem.configuration.verbose
ENV['PATH'] = 'C:\\DevKit\\bin;C:\\DevKit\\mingw\\bin;' + ENV['PATH']
end
ENV['RI_DEVKIT'] = 'C:\\DevKit'
ENV['CC'] = 'gcc'
ENV['CXX'] = 'g++'
ENV['CPP'] = 'cpp'
end
end
# :DK-END:


The other DevKit installed file (devkit.rb) is meant to be _manually_ required rather than being an RG helper. It brings the DevKit artifacts onto PATH, etc whenever you add it to a script via `require "devkit"` or from the command line via `-rdevkit`. It's meant to help scenarios like those documented in the DevKit wiki page as well as this thread's issue. Note that unlike operating_system.rb, the DevKit artifacts can remain on PATH and the other env vars for a longer time period. Here's the devkit.rb on my system:

# enable RubyInstaller DevKit usage as a vendorable helper library
unless ENV['PATH'].include?('C:\\DevKit\\mingw\\bin') then
puts 'Temporarily enhancing PATH to include DevKit...'
ENV['PATH'] = 'C:\\DevKit\\bin;C:\\DevKit\\mingw\\bin;' + ENV['PATH']
end
ENV['RI_DEVKIT'] = 'C:\\DevKit'
ENV['CC'] = 'gcc'
ENV['CXX'] = 'g++'
ENV['CPP'] = 'cpp'


Jon

Jon

unread,
Apr 12, 2012, 3:56:33 PM4/12/12
to rubyin...@googlegroups.com
> > That being said, why doesn't operating_system.rb just use 'require devkit'?

Forgot to add that, even though the purpose of the two files is different, we may be able to DRY up operating_system.rb by putting `require "devkit"` inside the `unless gem_installer.spec.extensions.empty?`.

Interesting idea.

If you want to tweak on it yourself, here are the relevant sections in part of the DevKit build recipe:

https://github.com/oneclick/rubyinstaller/blob/master/resources/devkit/dk.rb.erb#L46-81

Jon

Jon

unread,
Apr 12, 2012, 4:09:47 PM4/12/12
to rubyin...@googlegroups.com


Uh-oh...curiosity killed me and I manually hacked my existing operating_system.rb ;)


C:\>type \ruby193\lib\ruby\site_ruby\1.9.1\rubygems\defaults\operating_system.rb


# :DK-BEG: override 'gem install' to enable RubyInstaller DevKit usage
Gem.pre_install do |gem_installer|
unless gem_installer.spec.extensions.empty?

require 'devkit'
end
end
# :DK-END:

C:\>gem install redcarpet
Fetching: redcarpet-2.1.1.gem (100%)


Temporarily enhancing PATH to include DevKit...

Building native extensions. This could take a while...
Successfully installed redcarpet-2.1.1
1 gem installed

Jon

---
Fail fast. Fail often. Fail publicly. Learn. Adapt. Repeat.
http://thecodeshop.github.com | http://jonforums.github.com/
twitter: @jonforums

jfacet

unread,
Apr 12, 2012, 6:01:31 PM4/12/12
to rubyin...@googlegroups.com
Thank you for ruby --help
Some basis missed me from the begining. Here is one :
In a ruby script you may write 
system 'del C:\Users\%Username%\.ruby_inline\ruby-1.9.1\Inline_Hello1*.*'
(%Username% is  an  environment variable)
but you have to write ENV["PATH"]  instead of 
system 'path'

=====================

Le jeudi 5 avril 2012 11:16:21 UTC+2, jfacet a écrit :

Justin Baker

unread,
Apr 12, 2012, 7:45:33 PM4/12/12
to rubyin...@googlegroups.com
On Thursday, April 12, 2012 5:01:31 PM UTC-5, jfacet wrote:
Thank you for ruby --help
Some basis missed me from the begining. Here is one :
In a ruby script you may write 
system 'del C:\Users\%Username%\.ruby_inline\ruby-1.9.1\Inline_Hello1*.*'
(%Username% is  an  environment variable)
but you have to write ENV["PATH"]  instead of 
system 'path'

 They're interchangeable, so you could do both either ways. 

So you can use ENV['username'] to access the username or system 'echo %USERNAME%'

Likewise %PATH% is a lot like ENV['path'], although you should understand that it is different.

One is accessing the variable directly through the system and allows you to use system commands, 
the other is wrapping them and allowing you to use and modify them in Ruby. Subtle difference,
but important enough to mention.

@Jon

Uh-oh...curiosity killed me and I manually hacked my existing operating_system.rb ;)

Haha, I totally did that before I asked. I thought there might be side-effects I didn't know about though.
  
But if you could just use require 'devkit' it would make it easier to do something crazy like
Gemify the devkit too.

But I don't really know the internals of any of that to know if it would be dangerous to do. I'll totally 
edit the recipe, make sure it works, and unless someone finds something terribly wrong with it
create a pull request to see if anyone else can spot any problems.

Justin

jfacet

unread,
Apr 13, 2012, 4:40:58 PM4/13/12
to rubyin...@googlegroups.com
When I say you have to write ENV["PATH"]  instead of system 'path' 
I mean I tried to change path using system call and it was without any effect.
The little ruby program I gave above with the result is copied below :
---------------------------
$stdout.sync = true 
system 'cd'

system 'path' 
print "*\n"
system "C:/DevKit/devkitvars.bat"
print "**\n"
system 'path'  
print "***\n"

gets
------------------
Ruby uses ENV['PATH'] and don't mind I change the path with a system  call.

Thanks




Le jeudi 5 avril 2012 11:16:21 UTC+2, jfacet a écrit :

Phillip Gawlowski

unread,
Apr 13, 2012, 4:53:07 PM4/13/12
to rubyin...@googlegroups.com
On Fri, Apr 13, 2012 at 10:40 PM, jfacet <jfa...@gmail.com> wrote:
> When I say you have to write ENV["PATH"]  instead of system 'path'
> I mean I tried to change path using system call and it was without any
> effect.

That's because each call to Kernel#system spawns a new shell:
http://ruby-doc.org/core-1.9.3/Kernel.html#method-i-system

It isn't as clear as possible, but the term "sub-shell" hints at it.

If you want to change the path Ruby uses, look at FileUtils[0], and
manipulating ENV["path"].

[0] http://ruby-doc.org/stdlib-1.9.3/libdoc/fileutils/rdoc/index.html

--
Phillip Gawlowski

gplus.to/phgaw | twitter.com/phgaw

A method of solution is perfect if we can forsee from the start,
and even prove, that following that method we shall attain our aim.
              -- Leibniz

jfacet

unread,
Apr 14, 2012, 12:06:35 PM4/14/12
to rubyin...@googlegroups.com
You are right : I was wrong. I understood it was not a good idea to change the path in a script with
system "path=C:/DevKit/bin;%path%" 
because Ruby use ENV['PATH']
but it does not explain that after changing the path by a system call the change is not visible with 
system 'path'

==========


Le jeudi 5 avril 2012 11:16:21 UTC+2, jfacet a écrit :

Luis Lavena

unread,
Apr 14, 2012, 12:13:13 PM4/14/12
to rubyin...@googlegroups.com
On Sat, Apr 14, 2012 at 1:06 PM, jfacet <jfa...@gmail.com> wrote:
> You are right : I was wrong. I understood it was not a good idea to change
> the path in a script with
> system "path=C:/DevKit/bin;%path%"
> because Ruby use ENV['PATH']
> but it does not explain that after changing the path by a system call the
> change is not visible with
> system 'path'
>

When you change PATH using ENV, it changes the PATH environment
variable for that process and any child process that gets spawn from
it.

When you change the path in a child process, that change is only
visible to itself and any other child process spawned by that, but
will not be available in the process that spawned it.

So:

ENV["FOO"] = "something"
system "echo %FOO%"

Will work and print "something"

system "SET BAR=abc"
puts ENV["BAR"]

Will not work because the change to ENV is only available to the child process.

Every time you do "system '...'" it spawns a new child process, so it
starts with a fresh copy of environment variables inherited from the
parent process (cmd.exe is the parent of ruby.exe which then is the
parent of the command you spawn with 'system')

When you modify ENV variables in ruby.exe these will not be persisted
in cmd.exe once ruby.exe terminates.

Hope that makes sense and clear all your doubts about it.

If you still have questions, there is plenty of bibliography about
Windows, Process and such that will be a definite good read for you to
get familiar with.

jfacet

unread,
Apr 14, 2012, 3:13:55 PM4/14/12
to rubyin...@googlegroups.com
Thank you for light !
==============


Le jeudi 5 avril 2012 11:16:21 UTC+2, jfacet a écrit :

jfacet

unread,
Apr 15, 2012, 4:24:28 AM4/15/12
to rubyin...@googlegroups.com
Happily in a Ruby program this works:
%x{chcp}
%x{chcp 1252}
%x{chcp }
#==========

Le jeudi 5 avril 2012 11:16:21 UTC+2, jfacet a écrit :

Luis Lavena

unread,
Apr 16, 2012, 10:02:19 AM4/16/12
to rubyin...@googlegroups.com
On Sun, Apr 15, 2012 at 5:24 AM, jfacet <jfa...@gmail.com> wrote:
> Happily in a Ruby program this works:
> %x{chcp}
> %x{chcp 1252}
> %x{chcp }

All the examples and what we discussed before, we talk about
environment variables.

This example has nothing to do with environment variables, it changes
the codepage of the host process (cmd.exe), affecting ruby (as child
process of it) and also any other command your fire from it.

Either way, be careful what you do and how you use those commands on
different computers.

jfacet

unread,
Apr 17, 2012, 12:52:52 PM4/17/12
to rubyin...@googlegroups.com
That's clear.
I have Ruby installed on Windows.
Do you know a place or a book that can help users of Ruby on Windows? This is the question. The following is to illustrate.
I like the possibility to run a (Ruby) program by clicking on its name or icon.
The first thing my first Ruby program does is to ask me what I want to do. It uses the Windows console which is the console Ruby offers. Then I have to change the codepage (I use such characters as É é ô é ñ € ). I have also to change the properties of the window console for each new window title: the font must be Lucida Console. Why : There is something wrong in the world of Windows. I don't know how to do that in a ruby program. (I don't understand yet the explanation in http://msdn.microsoft.com/en-us/library/ms686200(v=vs.85).aspx and I did not find any example.
I change properties  with the mouse when I use a new program.)
Then I can go ahead. I use _getch,  _kbhit  and _putch (I think within Win32 API - C Run-Time Libraries) to read keystrokes to the console and to write on the console. Why: because it works and autocompletion is possible.
In that case (autocompletion) I would like to change color of characters. I tried ansicon one year ago without success.
To finish with (using a console with) Ruby on Windows , I would like to be the more as possible Windows free (independent). 
I just try :
#-----------------------
# coding: Windows-1252
require 'readline'
  loop do
    # line = Readline::readline('Votre réponse : ')
    line = Readline::readline('Your answer: ')
    break if line.nil? || line == 'quit'
    Readline::HISTORY.push(line)
    puts "You typed: #{line}"
  end
#------------------------
but I have some problems to solve with or without # coding: Windows-1252 
either I can type [é][è][ç][à] and break is quite impossible
either éèçà becomes  ‚Š‡…
with line = Readline::readline('Votre réponse : ')
I get 
rbreadline.rb:3394:in `[]=': incompatible character encodings: Windows-1252 and ASCII-8BIT (Encoding::CompatibilityError) 
if the first character is é
or
rbreadline.rb:3138:in `[]=': incompatible character encodings: ASCII-8BIT and Windows-1252 (Encoding::CompatibilityError) 
after the first character

With SciTE I get better result than when I click on the program name.
Be happy.
Reply all
Reply to author
Forward
0 new messages