On Wednesday 14 December 2011 19:15:22 anatoly techtonik wrote: > On Wed, Dec 14, 2011 at 7:09 PM, Hugo Parente Lima > > <[email protected]>wrote: > > On Wednesday 14 December 2011 12:05:57 anatoly techtonik wrote: > > > Hello, > > > > > > Is it possible to generate bindings for C libraries with shiboken? > > > > Yes you can, maybe shiboken isn't the better tool to bind C code, but it > > can > > do the job, and if you want a nicer and more OO API for your bindings you > > can > > do what Marcelo did here: > > > > http://www.setantas.net/blog/2011/03/08/python-bindings-for-libepub-using > > - shiboken/ > > This tutorial requires writing C++ wrapper around C code. Is it possible to > avoid that?
Yes it is, the C++ wrapper was done just to be able to use libepub in the OO
way in Python, but you can avoid that.
> > You also need to care care of putting all your includes inside a "extern
> > C",
> > because shiboken generates C++ code.
> Could you, please, expand this a bit? Do I need to do this in avbin.h file,
> or in generated .cpp/.h files?
When linking C code using a C++ compiler you must tell the C++ compiler that
the function is a C function, not a C++ function, you do this putting the
function declaration inside a block like:
extern "C" {
}
Some C libraries already do that in their headers, but if your library doesn't
do that you need to find a way to have all your C includes inside a extern "C"
block.
The problem is that Shiboken was meant to be used to wrap C++ code, not C, so
the code generator doesn't write the "extern C" before including the library
headers and you need to find a way to do that. Thinking a bit I don't know if
there's a clean way to do that with the current version of Shiboken.
> (If I was comfortable with C/C++, I would probably already created Python
> binding by hand).
>
> > I understand that C is a subset of C++, but I can't generate anything
> > from
> >
> > > C header file.
> > > For example, I want to create binding for avbin_get_version() function
> > > available from
> > > https://github.com/AVbin/AVbin/blob/master/include/avbin.h
> > >
> > > I do:
> > > $ shiboken lib/AVbin/include/avbin.h typesystem.xml
> > >
> > > Where typesystem.xml is the following:
> > >
> > > <?xml version="1.0"?>
> > >
> > > <!-- the name of the module as it will be imported from Python-->
> > > <typesystem package='AVbin'>
> > >
> > > <function signature='int avbin_get_version()' rename='version'/>
> > >
> > > </typesystem>
> > >
> > >
> > > First of all it always complains about "No C++ classes found!"
> >
> > You can ignore this message.
> >
> > > Then I see the message:
> > > Global function 'int avbin_get_version()' is specified in typesystem,
> > > but not defined. This could potentially lead to compilation errors.
> > >
> > > If I modify the <function> with signature='avbin_get_version()' I get
> > >
> > > another error:
> > > skipping function '::avbin_get_version', unmatched return type 'int'
> >
> > Probably this function wasn't found in your global header, the header
> > file read by shiboken to find what classes/function can be bound, look
> > at the log
> > files generated by the generator.
>
> They are empty. 1032 bytes each.
> Console output: http://pastebin.com/fU7rzmXi
> Generated files:
> - out/AVbin/avbin_module_wrapper.cpp - http://pastebin.com/GUkTiksN
> - out/AVbin/avbin_python.h - http://pastebin.com/KmGDW8xi
No, I meant the log files created by the generator, something like
mjb_rejected_functions.log, the log must explain why the functions were
rejected.
> I've uploaded the project to:
> https://bitbucket.org/techtonik/shiboken-avbin
--
Hugo Parente Lima
INdT - Instituto Nokia de Tecnologia
signature.asc
Description: This is a digitally signed message part.
_______________________________________________ PySide mailing list [email protected] http://lists.pyside.org/listinfo/pyside
