# Requiring extensions

**URL:** <https://www.ruby-forum.com/t/requiring-extensions/47879>\
**Category:** Ruby\
**Created:** [November 14, 2005, 8:53pm UTC](https://www.ruby-forum.com/t/requiring-extensions/47879 "2005-11-14T20:53:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e19b73/32.png) [@hans](https://www.ruby-forum.com/u/hans)\
**Post date:** [November 14, 2005, 8:53pm UTC](https://www.ruby-forum.com/t/requiring-extensions/47879/1 "2005-11-14T20:53:02Z")

</div>

I’m wrapping a library with swig, and I’d like to also implement some  
rubyisms for it in a regular ruby file. So I have:

ext/sndfile/extconf.rb  
ext/sndfile/sndfile.i  
ext/sndfile/sndfile.h  
lib/sndfile.rb

I’d like to have lib/sndfile.rb require the shared library. In the past  
I’ve done this with require ‘foo.so’, which worked great on linux but it  
occurs to me that it’s not very cross-platform. (On my iBook for example  
the output is sndfile.bundle)

Is there an elegant way to require the shared library and not the ruby  
lib? Or do I just need to name my shared library something else? (or  
vice versa) I’d like people to just be able to do

require ‘sndfile’

---

<div class="post-metadata">

**Author:** ![hans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e19b73/32.png) [@hans](https://www.ruby-forum.com/u/hans)\
**Post date:** [November 14, 2005, 11:47pm UTC](https://www.ruby-forum.com/t/requiring-extensions/47879/2 "2005-11-14T23:47:37Z")

</div>

On Tue, Nov 15, 2005 at 04:52:16AM +0900, Hans F. wrote:

> occurs to me that it’s not very cross-platform. (On my iBook for example  
> the output is sndfile.bundle)

this might help you:

require ‘rbconfig’  
[RUBY\_PLATFORM, RUBY\_VERSION] # =\> [“i686-linux”, “1.8.3”]  
Config::CONFIG[“DLEXT”] # =\> “so”

---

<div class="post-metadata">

**Author:** ![hans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e19b73/32.png) [@hans](https://www.ruby-forum.com/u/hans)\
**Post date:** [November 15, 2005, 4:06am UTC](https://www.ruby-forum.com/t/requiring-extensions/47879/3 "2005-11-15T04:06:14Z")

</div>

Hi,

At Tue, 15 Nov 2005 04:52:16 +0900,  
Hans F. wrote in [ruby-talk:165742]:

> I’d like to have lib/sndfile.rb require the shared library. In the past  
> I’ve done this with require ‘foo.so’, which worked great on linux but it  
> occurs to me that it’s not very cross-platform. (On my iBook for example  
> the output is sndfile.bundle)

“.so” is handled specically as the platform dependent suffix,  
i.e., “.bundle” on MacOSX.

---

<div class="post-metadata">

**Author:** ![hans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e19b73/32.png) [@hans](https://www.ruby-forum.com/u/hans)\
**Post date:** [November 15, 2005, 5:45am UTC](https://www.ruby-forum.com/t/requiring-extensions/47879/4 "2005-11-15T05:45:26Z")

</div>

On Tue, 15 Nov 2005 at 12:03 +0900, nobuyoshi nakada wrote:

> “.so” is handled specically as the platform dependent suffix,  
> i.e., “.bundle” on MacOSX.

So it does. I wonder what I fat-fingered when I thought I tried this in  
irb. Thank you both for your answers.
