Subject:
Re: [ruby-ffi] Re: newbie question ffi on OsX
From:
Wayne Meissner
Date:
3/9/10 8:46 PM
To:
ruby-ffi@googlegroups.com

You are now the honorary universal binary expert for ruby-ffi on
MacOS.  Turn your email thread into a FAQ and put it up on the wiki.


On 10 March 2010 00:56, macarthy <justin.maccarthy@gmail.com> wrote:
> Answering my own question, since I can't recompile the lib as 64bit I
> was able to run ruby as 32 bit and ffi works fine, Commands and output
> below.
>
> $ lipo -info /usr/local/lib/libmylib.dylib
> Non-fat file: /usr/local/lib/libmylib.dylib is architecture: i386
>
> $ lipo -detailed_info /usr/bin/ruby
> Fat header in: /usr/bin/ruby
> fat_magic 0xcafebabe
> nfat_arch 3
> architecture x86_64
>    cputype CPU_TYPE_X86_64
>    cpusubtype CPU_SUBTYPE_X86_64_ALL
>    offset 4096
>    size 14176
>    align 2^12 (4096)
> architecture i386
>    cputype CPU_TYPE_I386
>    cpusubtype CPU_SUBTYPE_I386_ALL
>    offset 20480
>    size 14112
>    align 2^12 (4096)
> architecture ppc7400
>    cputype CPU_TYPE_POWERPC
>    cpusubtype CPU_SUBTYPE_POWERPC_7400
>    offset 36864
>    size 13904
>    align 2^12 (4096)
>
>
> $ arch -arch i386 /usr/bin/ruby libmylib.rb
>
>
>> Hi all,
>>
>> Can someone explain this error ? Obviously an architecture mismatch of
>> some sort, how does one got about fixing this? Or compile libmylib as
>> a different arch (or as several ? )
>>
>> /Library/Ruby/Gems/1.8/gems/ffi-0.6.2/lib/ffi/library.rb:61:in
>> `ffi_lib': Could not open library 'libmylib.dylib':
>> dlopen(libmylib.dylib, 9): no suitable image found.  Did find:
>> (LoadError)
>>
>> /usr/local/lib/libmylib.dylib: mach-o, but wrong architecture. Could
>> not open library 'libmylib': dlopen(libmylib, 9): image not found
>>         from /Library/Ruby/Gems/1.8/gems/ffi-0.6.2/lib/ffi/library.rb:
>> 43:in `map'
>>         from /Library/Ruby/Gems/1.8/gems/ffi-0.6.2/lib/ffi/library.rb:
>> 43:in `ffi_lib'
>>         from xxx.rb:14
>>
>> otool gives me this ...
>>
>>  otool -h /usr/local/lib/libmylib.dylib
>>
>> /usr/local/lib/libmylib.dylib:
>> Mach header
>>       magic cputype cpusubtype  caps    filetype ncmds sizeofcmds
>> flags
>>  0xfeedface       7          3  0x00          6    20       2404
>> 0x00118085
>>
>> Thanks
>