[Tioga-users] tutorial on extending ruby in c
Bill Paxton
paxton at kitp.ucsb.edu
Sat Jun 3 18:00:22 EDT 2006
On Jun 3, 2006, at 1:29 PM, Edwin wrote:
> This will also finally teach me how to extend ruby programs in c.
> If anyone has a good tutorial on that please let me know.
Hi Edwin,
A while back I put together a small example in response to another
Tioga user. You might want to give this a try.

1) create a new folder and place the 4 files in it (no other c files
please!)
2) do
ruby extconf.rb
make
make install
The 'ruby extconf.rb' should create a Makefile in the folder.
The 'make' should compile spa.c and then create a dynamic lib.
The 'make install' should put the dynamic lib into your Ruby release
(this may need superuser status of course).
3) check it by
ruby myspa_test.rb
This should produce terminal output like this:
Loaded suite myspa_test
Started
s.calc * 0.5e-9 is 3.141591
.
Finished in 0.000506 seconds.
1 tests, 4 assertions, 0 failures, 0 errors
If that works, you are off and running! If not, let me know where
things go bad.
Cheers,
Bill
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/tioga-users/attachments/20060603/d6d6612a/attachment.htm
-------------- next part --------------
A non-text attachment was scrubbed...
Name: extconf.rb
Type: text/x-ruby-script
Size: 107 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/tioga-users/attachments/20060603/d6d6612a/attachment.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: myspa_test.rb
Type: text/x-ruby-script
Size: 399 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/tioga-users/attachments/20060603/d6d6612a/attachment-0001.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: spa.h
Type: application/octet-stream
Size: 185 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/tioga-users/attachments/20060603/d6d6612a/attachment.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: spa.c
Type: application/octet-stream
Size: 1551 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/tioga-users/attachments/20060603/d6d6612a/attachment-0001.obj
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/tioga-users/attachments/20060603/d6d6612a/attachment-0001.htm
More information about the Tioga-users
mailing list