objective-c - 将 Cocoa header 链接到 ruby​​ C 扩展

标签 objective-c c ruby makefile ruby-c-extension

我正在为 ruby​​ 开发一个 C 扩展,但我需要包含来自 IOBluetooth 框架的 header ,特别是:

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

一切都编译正常,但在运行时,扩展错误:

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

我相当确定这与未包含在链接过程中的框架有关,但我不确定原因。任何帮助将不胜感激

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')

生成的 MakeFile: http://paste.wilhall.com/25

更新: 我修改了 Makefile 以便库静态链接;仍然遇到同样的错误,但这次是在链接时。

奇怪的是,我的 extconf.rb 文件中的 have_header 可以正常找到这些头文件。

更新: 我从系统日志文件中提取了以下内容:

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

如果我没记错的话,EXC_BAD_ACCESS (SIGABRT) 通常与 GC 问题有关?将调查并发布结果

最佳答案

这看起来太简单了,所以我可能会离开,但从你发布的内容来看它看起来是正确的。看起来问题不在于 header ,而是您没有链接 IOBluetooth 框架本身。您是否在任何地方指定了诸如 -framework IOBluetooth 之类的内容?

关于objective-c - 将 Cocoa header 链接到 ruby​​ C 扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12887639/

相关文章:

ios - 以编程方式将 iPhone 静音是否合法?

ios - JASidePanels 示例 2 使用 Storyboard : crash

c - C 中 printf 的多个 while 循环

java - ruby 中是否有一些像 java httpclient 这样的库

objective-c - NSDistributedNotificationCenter 通知失败?

iphone - 写入钥匙串(keychain)失败

C printf() 不返回值

使用带有输入和输出流的 ProcessBuilder 的 Java 程序不起作用

html - Rails 将 div 添加到通过验证的表单字段,例如失败时的 "fields_with_errors"div

ruby-on-rails - 生成和发布基于 Ruby 的 REST API 文档