.rb file includes c-extension of same name?

B

Bill Kelly

Hi,

I have foo.rb and foo.so, the C-extension part of the module.

Inside foo.rb, I can put, require 'foo.so', and it works fine,
allowing other modules to say require 'foo', and have the .rb
be loaded, which in turn loads the C-extension.

I'm wondering if there's a recommended platform-independent
way to do this? For instance, on OS X, C-extensions end in
".bundle" not ".so".

I wouldn't mind even saying require "foo.#{DLEXT}", if there
were such a thing available from ruby.

Is there a recommended way to have a .rb file require a
C-extension file of the same name in a platform-independent
way? Or is the preferred solution to alter the name of one
of the two files?


Thanks,

Bill
 
A

ara.t.howard

Hi,

I have foo.rb and foo.so, the C-extension part of the module.

Inside foo.rb, I can put, require 'foo.so', and it works fine,
allowing other modules to say require 'foo', and have the .rb
be loaded, which in turn loads the C-extension.

I'm wondering if there's a recommended platform-independent
way to do this? For instance, on OS X, C-extensions end in
".bundle" not ".so".

I wouldn't mind even saying require "foo.#{DLEXT}", if there
were such a thing available from ruby.

Is there a recommended way to have a .rb file require a C-extension file of
the same name in a platform-independent
way? Or is the preferred solution to alter the name of one
of the two files?


Thanks,

Bill

harp:~ > ruby -r yaml -r rbconfig -e' y Config::CONFIG '|egrep DLEXT
DLEXT2: ""
DLEXT: so


-a
 
B

Bill Kelly

From: said:
harp:~ > ruby -r yaml -r rbconfig -e' y Config::CONFIG '|egrep DLEXT
DLEXT2: ""
DLEXT: so

Aha! TYVM. I'd been grepping the C source. . . .


Regards,

Bill
 
G

George Ogata

Bill Kelly said:
Hi,

I have foo.rb and foo.so, the C-extension part of the module.

Inside foo.rb, I can put, require 'foo.so', and it works fine,
allowing other modules to say require 'foo', and have the .rb
be loaded, which in turn loads the C-extension.

I'm wondering if there's a recommended platform-independent
way to do this? For instance, on OS X, C-extensions end in
".bundle" not ".so".

I wouldn't mind even saying require "foo.#{DLEXT}", if there
were such a thing available from ruby.

Is there a recommended way to have a .rb file require a
C-extension file of the same name in a platform-independent
way? Or is the preferred solution to alter the name of one
of the two files?


Thanks,

Bill

An alternative: call the C bit "foo_ext.so" (say) and then in "foo.rb"
just do "require 'foo_ext'"?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top