Re: [Vala] Using a C library



From: Justin Brown <justin brown fandingo org>

To: Jens Georg <mail jensge org>
Sent: Monday, 20 April 2015, 23:41
Subject: Re: [Vala] Using a C library

T hanks so much for the replies! I'm starting to make some slow progress,
but holy cow is that confusing coming from a friendlier language (at least

when it comes to library loading). 


Thanks for sharing your experience, it has been useful to me as I hope you see below.


Here's the stream of errors that I went through:

2) Move the vala method for sp_error_message out of the enum, out of the
namespace, all over the place, did the hokey pokey, and turned myself
around.


This is the essence of what you are doing - creating an interface between
your Vala code and the C code being generated. You can have the function in 

the enum, but put

[CCode ( cname="sp_error_message" )]

before the function. I think you already know how to see the C code generated,
but if you don't use the --ccode switch with the valac command. You will notice
that without the cname attribute the enum name is prefixed to the function
name in C. With the cname attribute the name is changed in the C, but you can still use
the method with your enum in Vala. Whether you want the method to be accessed
within the enum is an API design choice.

You may also want to browse through 

https://git.gnome.org/browse/vala/tree/vapi
and look at some of the VAPI's there to get some ideas on how to progress.
Note that a lot of those bindings are now automatically generated using
GIR, so those one's won't be much help to you.

If you persevere and get a working VAPI then please share your work. See
https://github.com/nemequ/vala-extra-vapis
8) `valac -lspotify spotify.vala`: unknown option -lspotify. Checks
manpage... `valac --library=spotify spotify.vala`: undefined reference to
`sp_error_message'. This couldn't be any less intuitive... Searches
internet. Duh, it's so obviously -Xcc=-lspotify. Stupid fandingo, how did
you not know better?



OK that is useful to know and sorry for the pain. It looks as though the answer to 

my question of what else a VAPI does is look for pkg-config details to find
the compiler options to pass. See:
https://wiki.gnome.org/Projects/Vala/ValaForCSharpProgrammers#Bindings
http://www.freedesktop.org/wiki/Software/pkg-config/
http://people.freedesktop.org/~dbn/pkg-config-guide.html

I've had a quick search and it looks as though a libspotify.pc file exists, e.g.
http://www.rpmfind.net//linux/RPM/sourceforge/o/os/osolinux/update/RPMS.l/libspotify-devel-12.1.51-3mgc30.x86_64.html
Check there is a .pc file in the package that provided your header files. Then can
you rename spotify.vala to spotify.vapi and try compiling with:
valac fandingo.vala --pkg gio-2.0 --pkg spotify --vapidir dir_you_vapi_is_in

This should avoid you manually passing details to the linker. I would be
grateful if you could confirm this.

There are a few exceptions. You have to manually link the glibc maths library, e.g.
http://valadoc.org/#!api=glib-2.0/GLib.Math.acos
Has the comment "Remember to link the math library: valac -X -lm ..." so that is
documented.


All the best with your project,

Al


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]