Linking Cocoa headers to ruby C extension
Asked Answered
C

2

6

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

Cynicism answered 14/10, 2012 at 23:45 Comment(1)
this is an awesome question +1Ronnironnica
E
1

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?

Enteric answered 17/10, 2012 at 18:38 Comment(1)
I apologize, the MakeFile I posted is a freshly generated one. I edited it to include IOBluetooth as a framework. See the last part of the question for the new part of the errorCynicism
D
1

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

Dom answered 22/10, 2012 at 9:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.