Search code examples
rubymotion

Rubymotion including a static library


I'm trying to add the a library to my Rubymotion project, it shows no errors but I can't seem to access the classes in the library, in my rakefile I have ...

app.vendor_project('vendor/iSpeechSDK', :static,
    :products => ["libiSpeechSDK.a"],
    :headers_dir => "Headers")

app.frameworks += ['iSpeechSDK']

The .a file and .h files in the Headers directory all exist

In my app_delegate I have this code ...

@sdk = iSpeechSDK.sharedSDK

But I get the error ...

Simulate ./build/iPhoneSimulator-5.0-Development/Mirror Mirror.app (main)> 2012-07-19 10:50:05.978 Mirror Mirror[26195:11903] app_delegate.rb:13:in application:didFinishLaunchingWithOptions:': undefined local variable or methodiSpeechSDK' for # (NameError) 2012-07-19 10:50:05.980 Mirror Mirror[26195:11903] * Terminating app due to uncaught exception 'NameError', reason: 'app_delegate.rb:13:in application:didFinishLaunchingWithOptions:': undefined local variable or methodiSpeechSDK' for # (NameError) ' * First throw call stack: (0xa88052 0x417d0a 0x207954 0x5c285 0x5bce1)


Solution

  • Answer from Laurent on Google Groups

    The problem is that the iSpeechSDK class name starts with a lower-case letter, which is not a valid constant name in Ruby.

    In the next release you will be able to do ISpeechSDK.sharedSDK (as you can already do to access constants or enumerations that also start with a lower-case letter), but right now, a workaround can be:

    NSClassFromString('iSpeechSDK').sharedSDK
    

    Also, copy the .bundle file into the resources folder? The build system will not do it automatically (it will only link the app against the .a library)