# Finding ruby.h

**URL:** <https://rubytalk.org/t/finding-ruby-h/51146>\
**Category:** ruby-talk\
**Created:** [14 January 2009 05:20 UTC](https://rubytalk.org/t/finding-ruby-h/51146 "2009-01-14T05:20:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Ky](https://avatars.discourse-cdn.com/v4/letter/j/c4cdca/32.png) [@John\_Ky](https://rubytalk.org/u/John_Ky)\
**Post date:** [14 January 2009 05:20 UTC](https://rubytalk.org/t/finding-ruby-h/51146/1 "2009-01-14T05:20:00Z")

</div>

Hi,

I'm building ruby extensions across many different OSes and architectures.

Does anyone know an easy way to find ruby.h on any given system?

I'm told that perl has a "perl -V" or @ENV variable which gives some paths I  
can look through for perl.h.

Does Ruby have an equivalent? Is there a better way to find ruby.h?

Thanks,

-John

---

<div class="post-metadata">

**Author:** ![Jeremy\_Hinegardner](https://avatars.discourse-cdn.com/v4/letter/j/65b543/32.png) [@Jeremy\_Hinegardner](https://rubytalk.org/u/Jeremy_Hinegardner)\
**Post date:** [14 January 2009 05:44 UTC](https://rubytalk.org/t/finding-ruby-h/51146/2 "2009-01-14T05:44:41Z")

</div>

This works on a couple of my systems:

&nbsp;&nbsp;&nbsp;&nbsp;require 'rbconfig'  
&nbsp;&nbsp;&nbsp;&nbsp;loc = File.join( Config::CONFIG['archdir'], 'ruby.h')  
&nbsp;&nbsp;&nbsp;&nbsp;if File.exist?( loc ) then  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts loc  
&nbsp;&nbsp;&nbsp;&nbsp;else  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "Unable to find ruby.h in #{loc}"  
&nbsp;&nbsp;&nbsp;&nbsp;end

enjoy,

-jeremy

> **···**
>
> On Wed, Jan 14, 2009 at 02:20:00PM +0900, John Ky wrote:
> 
> > Hi,
> > 
> > I'm building ruby extensions across many different OSes and architectures.
> > 
> > Does anyone know an easy way to find ruby.h on any given system?
> > 
> > I'm told that perl has a "perl -V" or @ENV variable which gives some paths I  
> > can look through for perl.h.
> > 
> > Does Ruby have an equivalent? Is there a better way to find ruby.h?
> 
> # --
> 
> Jeremy Hinegardner jeremy@hinegardner.org

---

<div class="post-metadata">

**Author:** ![LaP](https://avatars.discourse-cdn.com/v4/letter/l/6f9a4e/32.png) [@LaP](https://rubytalk.org/u/LaP)\
**Post date:** [14 January 2009 16:59 UTC](https://rubytalk.org/t/finding-ruby-h/51146/3 "2009-01-14T16:59:11Z")

</div>

John Ky a écrit :

> I'm building ruby extensions across many different OSes and architectures.
> 
> Does anyone know an easy way to find ruby.h on any given system?
> 
> I'm told that perl has a "perl -V" or @ENV variable which gives some paths I  
> can look through for perl.h.
> 
> Does Ruby have an equivalent? Is there a better way to find ruby.h?

My first idea for this kind of problem would be to check GNU autoconf / configure.sh

LaP

---

<div class="post-metadata">

**Author:** ![Dave\_Harrison](https://avatars.discourse-cdn.com/v4/letter/d/4491bb/32.png) [@Dave\_Harrison](https://rubytalk.org/u/Dave_Harrison)\
**Post date:** [14 January 2009 17:39 UTC](https://rubytalk.org/t/finding-ruby-h/51146/4 "2009-01-14T17:39:06Z")

</div>

John Ky wrote:

> [Note: parts of this message were removed to make it a legal post.]
> 
> Hi,
> 
> I'm building ruby extensions across many different OSes and architectures.
> 
> Does anyone know an easy way to find ruby.h on any given system?
> 
> I'm told that perl has a "perl -V" or @ENV variable which gives some paths I  
> can look through for perl.h.
> 
> Does Ruby have an equivalent? Is there a better way to find ruby.h?
> 
> Thanks,
> 
> -John

I have used CMake to make a SWIG wrapper with success on Windows and  
Linux. The FindRuby.cmake script does all of the hard work at locating  
Ruby.h. CMake-2.6.2 (and possibly others) includes FindRuby.cmake and  
can be used like so:

(Note: FindRuby.cmake doesn't export RUBY\_FOUND, so I create that var  
myself)

Main CMakeLists.txt:  
...  
SET(RUBY\_FOUND FALSE)  
FIND\_PACKAGE( Ruby)  
if(RUBY\_INCLUDE\_PATH AND RUBY\_LIBRARY)  
SET(RUBY\_FOUND TRUE)  
endif(RUBY\_INCLUDE\_PATH AND RUBY\_LIBRARY)  
...  
if(RUBY\_FOUND)  
INCLUDE\_DIRECTORIES( ${RUBY\_INCLUDE\_PATH})  
endif(RUBY\_FOUND)  
...

CMakeLists.txt for each library in app:  
...  
if(RUBY\_FOUND)  
SET\_SOURCE\_FILES\_PROPERTIES(RbDynamic.i PROPERTIES SWIG\_FLAGS "-autorename")  
SET\_SOURCE\_FILES\_PROPERTIES(RbDynamic.i PROPERTIES CPLUSPLUS ON)  
SET\_SOURCE\_FILES\_PROPERTIES(RbDynamic.i PROPERTIES SWIG\_FLAGS "-includeall")  
SWIG\_ADD\_MODULE( rbdynamic ruby RbDynamic.i )  
SWIG\_LINK\_LIBRARIES( rbdynamic ${RUBY\_LIBRARY}  
${MIIND\_LIBRARY\_PREFIX}dynamic  
)  
endif(RUBY\_FOUND)  
...

CMake is a doddle to use if you don't already know it, and is cross  
platform (I've only used Windows and Linux). Check it out at [www.cmake.org](http://www.cmake.org)

Dave H.

---

<div class="post-metadata">

**Author:** ![John\_Ky](https://avatars.discourse-cdn.com/v4/letter/j/c4cdca/32.png) [@John\_Ky](https://rubytalk.org/u/John_Ky)\
**Post date:** [15 January 2009 04:53 UTC](https://rubytalk.org/t/finding-ruby-h/51146/5 "2009-01-15T04:53:22Z")

</div>

Hi all,

Thanks everyone for your help. I've settled with this solution as I've  
already got it working. Very much appreciated!

-John

> **···**
>
> On Wed, Jan 14, 2009 at 4:44 PM, Jeremy Hinegardner \<jeremy@hinegardner.org\>wrote:
> 
> > On Wed, Jan 14, 2009 at 02:20:00PM +0900, John Ky wrote:  
> > \> Hi,  
> > \>  
> > \> I'm building ruby extensions across many different OSes and  
> > architectures.  
> > \>  
> > \> Does anyone know an easy way to find ruby.h on any given system?  
> > \>  
> > \> I'm told that perl has a "perl -V" or @ENV variable which gives some  
> > paths I  
> > \> can look through for perl.h.  
> > \>  
> > \> Does Ruby have an equivalent? Is there a better way to find ruby.h?
> > 
> > This works on a couple of my systems:
> > 
> > &nbsp;&nbsp;&nbsp;require 'rbconfig'  
> > &nbsp;&nbsp;&nbsp;loc = File.join( Config::CONFIG['archdir'], 'ruby.h')  
> > &nbsp;&nbsp;&nbsp;if File.exist?( loc ) then  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts loc  
> > &nbsp;&nbsp;&nbsp;else  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "Unable to find ruby.h in #{loc}"  
> > &nbsp;&nbsp;&nbsp;end
> > 
> > enjoy,
> > 
> > -jeremy
> > 
> > # --
> > 
> > Jeremy Hinegardner jeremy@hinegardner.org
