Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linking Cocoa headers to ruby C extension

I am working on a C extension for ruby, but I need to include headers from the IOBluetooth framework, specifically:

#import <IOBluetooth/objc/IOBluetoothDeviceInquiry.h>
#import <IOBluetooth/IOBluetoothUserLib.h>

Everything compiles fine, but at runtime, the extension errors:

path/to/file.rb:1:in `require_relative': dlopen(/path/to/extension.bundle, 9):
Symbol not found: _OBJC_CLASS_$_IOBluetoothDeviceInquiry (LoadError)

I am fairly sure this has something to do with the framework not being included in the linking process, but I'm not sure why. Any help would be greatly appreciated

extconf.rb:

# Loads mkmf which is used to make makefiles for Ruby extensions
require 'mkmf'

# Give it a name
extension_name = 'bluetooth'

dir_config(extension_name)

create_makefile(extension_name, 'bluetooth')

Generated MakeFile: http://paste.wilhall.com/25

UPDATE: I modified the Makefile so that the library statically links; still experiencing the same error, but this time when linking.

Oddly, have_header in my extconf.rb file finds these header files fine.

UPDATE: I have pulled the following from the system log files:

Process:         ruby [951]
Path:            /usr/local/bin/ruby
Identifier:      ruby
Version:         0
Code Type:       X86-64 (Native)
Parent Process:  bash [468]
User ID:         501

Date/Time:       2012-10-17 14:06:57.425 -0400
OS Version:      Mac OS X 10.8.1 (12B19)
Report Version:  10

Crashed Thread:  0  Dispatch queue: com.apple.main-thread

Exception Type:  EXC_BAD_ACCESS (SIGABRT)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000010

If I remember correctly, EXC_BAD_ACCESS (SIGABRT) is often related to a GC issue? Will look into it and post results

like image 869
WilHall Avatar asked Oct 14 '12 23:10

WilHall


2 Answers

This seems too simple, so I might be off, but it looks right from what you've posted. It looks like the problem isn't the headers, but that you aren't linking the IOBluetooth framework itself. Are you specifying anything like -framework IOBluetooth anywhere?

like image 102
Chuck Avatar answered Oct 29 '22 02:10

Chuck


Make sure you included

-framework Foundation System/Library/Frameworks/IOBluetooth.framework/IOBluetooth

In your makeFile. Be sure you have the framework in the right directory. But if you can compile it, link it, your IOBluetooth seems now in your binary.

By the way you are trying to access a pointer at address 0x02, this is what creating the crash. I'm not sure it's related to IOBluetooth anymore

like image 24
Mr Bonjour Avatar answered Oct 29 '22 04:10

Mr Bonjour