loading a c library

98 views
Skip to first unread message

Kenny Lovrin

unread,
May 21, 2012, 9:19:21 AM5/21/12
to rubymotion
hi there

i'm having some issues understanding how to load a c library. i've
kind of guesstimated what to put in the rake file, and it does
compile, but i can't call any of the functions that the library
exposes. so the question is if i need to do something more? like
generate any bridge support files etc - and in that case how to do it.

just for reference i've done like this now in my rake file, which
doesn't exactly look like the docs i think. the library (libspotify)
comes as a framework, but i just pointed it to the actual files as i
was hoping that is correct:

app.vendor_project "vendor/libspotify.framework", :static,
:products => ["libspotify"],
:headers_dir => "Heiders"

calling a function like sp_session_create() for example then results
in the following:
*** Terminating app due to uncaught exception 'NoMethodError', reason:
' 42:in `initialize': undefined method `sp_session_create' for
#<Models::Spotify:0x8e3eca0> (NoMethodError)
from root_view_controller.rb:8:in `viewDidLoad'
from 189:in `application:didFinishLaunchingWithOptions:

my understanding is that it should be possible to load c libs, but
it's not completely clear what is needed to make it work. :)

any input on this?

thanks!

kenny

Andrew Vega

unread,
May 21, 2012, 12:30:21 PM5/21/12
to rubym...@googlegroups.com
It is my understanding that you will need to have an objective-c wrapper around the c framework to make the method calls. I'm not sure exactly how this works with your current project, but this may provide some solution:

https://github.com/spotify/cocoalibspotify

Regards,

Andrew Vega

Kenny Lovrin

unread,
May 22, 2012, 11:29:26 AM5/22/12
to rubymotion
Hey

Thanks, that kind of make sense I guess. However, as I understand it
is possible to use Obj-C code directly in the RubyMotion project. But
what does this mean specifically, does it mean I can just add some .h
and .m classes and it will compile? I tried doing that, but that
didn't work, so I'm guessing that I either have to put them somewhere
specific or actually build them as a library from within Xcode for
example. I could do the latter, but to me that somehow defeats the
purpose of being able to "mix" ruby and obj-c.

What I'm trying to say, I'm fine with writing wrappers in Obj-C, but
I'd like to do it within the same environment as I use for ruby and
not go through Xcode or any pre-build libraries of my own code if you
know what I mean.

Kenny

Andrew Vega

unread,
May 22, 2012, 10:26:44 PM5/22/12
to rubym...@googlegroups.com
I hear what you are saying. I am interested in knowing the answer to this as well.

Andrew
Reply all
Reply to author
Forward
0 new messages