XCode, Mac OS X, Ruby C Extension

Hi,

i 've a problem trying to compile a simple C Extension, that actually do
nothing, only print an hello message.
If from XCode i create and build a new Ruby C Extension, then i try to
recall it from a ruby script, that use the ruby interpreter compiled
from MacPort , a BUS ERROR is returned, au contraire, if i use the
Leopard’s ruby interpreter, it works.
Already tried to change the XCode project target properties to 32 and
64bit but no way to work with that ,and i do non understand why, 2 ruby
interpreters can’t use the same c extension.

Thanks

On Mar 22, 2008, at 06:10 , Wladjmir W. wrote:

interpreters can’t use the same c extension.
2 different ruby interpreters, built in entirely different ways, are
not necessarily compatible with each other. You need to build each and
every extension for a specific interpreter. Take a look at how inline
works:

1.8/universal-darwin9.0 -I /usr/include -o “/Users/ryan/.ruby_inline/
Inline_Demo_5d41.bundle” “/Users/ryan/.ruby_inline/
Inline_Demo_5d41.c” -flat_namespace -undefined suppress’

Output:

Built successfully

hello

Then go look at inline.rb to see what information it gathers and how.

On Mar 22, 2008, at 8:10 AM, Wladjmir W. wrote:

64bit but no way to work with that ,and i do non understand why, 2
ruby
interpreters can’t use the same c extension.

Thanks

Posted via http://www.ruby-forum.com/.

Since the built-in Leopard build of Ruby is the future for OS X, I
would recommend focusing your efforts there. (and maybe 1.9…)
Clearly, at this time, Apple is taking Ruby pretty seriously.
MacPorts can introduce additional complexities to the situation. If
you still want to get it working, by all means, do it. I’m just
saying that the future of a stable, predictable OS X Ruby
distribution is likely to be the one that is bundled.
On the other hand, if you have older Macs you need to support that
does not fix things, does it?

Let’s just hope the MS and Mac versions of Ruby don’t diverge too
much… (beyond their native Frameworks of course)

On 22 Mar, 13:10, Wladjmir W. [email protected] wrote:

Hi,

i 've a problem trying to compile a simple C Extension, that actually do
nothing, only print an hello message.
If from XCode i create and build a new Ruby C Extension, then i try to
recall it from a ruby script, that use the ruby interpreter compiled
from MacPort , a BUS ERROR is returned, au contraire, if i use the

I’d recommend using mkmf to build your extension as part of the
installation process, rather than trying to build it yourself. That
way your extension should work on any Ruby installation. I don’t know
what formal documentation there is for it; personally I just copied
the extconf.rb script from another project (which copied it from
another project…), so feel free to repeat the pattern if it helps.

Obviously if you want to distribute a binary version of your extension
for the convenience of your users (since not all OS X users have gcc
installed by default), you’ll need to create a separate distribution
for each Ruby build you want to support. But hey, you can deal with
that problem when you get to it.

HTH

has

Hi,

The Xcode template will produce an extension that may only work for
the version of Ruby that ships with the system. I don’t know why it
doesn’t work with the version in MacPorts, could you provide more
feedback about this (like a backtrace)? Maybe it’s because the
extension is built 2-way fat (for i386 and ppc) by default.

Anyway if you want to write an extension that should be portable with
different versions of Ruby, as others suggested you should use mkmf.

Laurent

Laurent S. wrote:

Hi,

The Xcode template will produce an extension that may only work for
the version of Ruby that ships with the system. I don’t know why it
doesn’t work with the version in MacPorts, could you provide more
feedback about this (like a backtrace)? Maybe it’s because the
extension is built 2-way fat (for i386 and ppc) by default.

Anyway if you want to write an extension that should be portable with
different versions of Ruby, as others suggested you should use mkmf.

Laurent

Thanks all,

i unistalled macport version of ruby… the simple way.
Just curious,it disturb me that my extension could not work on another
machine, and i do not understand why, afterall the ruby source files are
the same.
if i build manually with extconf -> make it work with both, then the
problem is some configuration on XCode? i would like to use RubyCocoa
for some project so i want to learn something more about how it works
with ruby.
i already tried to build only i38, the only error i get is BUS ERROR -
Abort trap follow the crash report :

Process: ruby [2450]
Path: /opt/local/bin/ruby
Identifier: ruby
Version: ??? (???)
Code Type: X86 (Native)
Parent Process: ruby [2441]

Date/Time: 2008-03-22 12:32:58.152 +0100
OS Version: Mac OS X 10.5.2 (9C31)
Report Version: 6

Exception Type: EXC_BAD_ACCESS (SIGABRT)
Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000000000000
Crashed Thread: 0

Thread 0 Crashed:
0 libSystem.B.dylib 0x911e80ea __kill + 10
1 libSystem.B.dylib 0x9125f3f2 raise + 26
2 libSystem.B.dylib 0x9126e9af abort + 73
3 libruby.dylib 0x000eb970 rb_exc_new + 0
4 libruby.dylib 0x0015b4b6 sigbus + 54
5 libSystem.B.dylib 0x911e65eb _sigtramp + 43
6 ??? 0xffffffff 0 + 4294967295
7 libruby.1.dylib 0x0034db48 rb_intern + 43
8 libruby.1.dylib 0x00309d83 rb_define_module + 32
9 RubyCExtTry.bundle 0x000a5f55 Init_RubyCExtTry + 27
(RubyCExtTry.c:20)
10 libruby.dylib 0x000e9e4e dln_load + 190
11 libruby.dylib 0x00107704 rb_require_safe + 1044
12 libruby.dylib 0x000f9492 rb_call0 + 706
13 libruby.dylib 0x000fa0ac rb_call + 284
14 libruby.dylib 0x000f6a71 rb_eval + 4929
15 libruby.dylib 0x00107a77 ruby_exec_internal + 151
16 libruby.dylib 0x00107ab6 ruby_exec + 22
17 libruby.dylib 0x00107aea ruby_run + 42
18 ruby 0x00001ffd 0x1000 + 4093
19 ruby 0x00001f96 start + 54

Thread 0 crashed with X86 Thread State (32-bit):
eax: 0x00000000 ebx: 0x9126e96f ecx: 0xbfffdf6c edx: 0x911e80ea
edi: 0xa00fe650 esi: 0x00000016 ebp: 0xbfffdf88 esp: 0xbfffdf6c
ss: 0x0000001f efl: 0x00000282 eip: 0x911e80ea cs: 0x00000007
ds: 0x0000001f es: 0x0000001f fs: 0x00000000 gs: 0x00000037
cr2: 0x00000000

Binary Images:
0x1000 - 0x1ffc +ruby ??? (???) /opt/local/bin/ruby
0x91000 - 0x92fff +plist.bundle ??? (???)
/Applications/Editors/TextMate.app/Contents/SharedSupport/Support/lib/osx/plist.bundle
0xa1000 - 0xa1ffa +wait.bundle ??? (???)
/opt/local/lib/ruby/1.8/i686-darwin9.2.0/io/wait.bundle
0xa5000 - 0xa5ffc +RubyCExtTry.bundle ??? (???)

/Users/wladj/RubyCExtTry/build/Release/RubyCExtTry.bundle
0xda000 - 0x185ffb +libruby.dylib ??? (???)
/opt/local/lib/libruby.dylib
0x300000 - 0x39dffb libruby.1.dylib ??? (???)
<7ed6bf45152b1d74844a0e3fdbba4899>
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/libruby.1.dylib
0x8fe00000 - 0x8fe2da53 dyld 96.2 (???)
<7af47d3b00b2268947563c7fa8c59a07> /usr/lib/dyld
0x91001000 - 0x91139ff7 libicucore.A.dylib ??? (???)
/usr/lib/libicucore.A.dylib
0x91179000 - 0x912d8ff3 libSystem.B.dylib ??? (???)
<4899376234e55593b22fc370935f8cdf> /usr/lib/libSystem.B.dylib
0x912d9000 - 0x9140bfef com.apple.CoreFoundation 6.5.1 (476.10)

/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
0x924b8000 - 0x924bffe9 libgcc_s.1.dylib ??? (???)
/usr/lib/libgcc_s.1.dylib
0x9258c000 - 0x92590fff libmathCommon.A.dylib ??? (???)
/usr/lib/system/libmathCommon.A.dylib
0x94755000 - 0x94780fe7 libauto.dylib ??? (???)
<42d8422dc23a18071869fdf7b5d8fab5> /usr/lib/libauto.dylib
0x957f4000 - 0x95851ffb libstdc++.6.dylib ??? (???)
<04b812dcec670daa8b7d2852ab14be60> /usr/lib/libstdc++.6.dylib
0x964a5000 - 0x96584fff libobjc.A.dylib ??? (???)
/usr/lib/libobjc.A.dylib
0xfffe8000 - 0xfffebfff libobjc.A.dylib ??? (???)
/usr/lib/libobjc.A.dylib
0xffff0000 - 0xffff1780 libSystem.B.dylib ??? (???)
/usr/lib/libSystem.B.dylib