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/
You also need to care care of putting all your includes inside a "extern C",
because shiboken generates C++ code.
> 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.
> So, obviously, shiboken is able to parse avbin.h and find
> avbin_get_version() function with 'int' return type, but why it complains
> that the function is not defined when the typesystem is fixed?
--
Hugo Parente Lima
INdT - Instituto Nokia de Tecnologia
On Wednesday 14 December 2011 12:05:57 anatoly techtonik wrote:Yes you can, maybe shiboken isn't the better tool to bind C code, but it can
> Hello,
>
> Is it possible to generate bindings for C libraries with shiboken?
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/
You also need to care care of putting all your includes inside a "extern C",
because shiboken generates C++ code.
> I understand that C is a subset of C++, but I can't generate anything fromYou can ignore this message.
> 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!"
Probably this function wasn't found in your global header, the header file
> 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'
read by shiboken to find what classes/function can be bound, look at the log
files generated by the generator.
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.
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
--
> > You also need to care care of putting all your includes inside a "extern> > C",When linking C code using a C++ compiler you must tell the C++ compiler that
> > 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?
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.
_______________________________________________ PySide mailing list PyS...@lists.pyside.org http://lists.pyside.org/listinfo/pyside
Historic reasons, besides the fact that the C++ parser we have was written in
C++. I already tried to create bindings for ApiExtractor (where the C++ parser
lives) using the current Shiboken and rewrite the generator in Python, but
it's a lot of work and I had no free time to do that so I forgot this idea.
As I said Shiboken was intended to be used to wrap C++ libraries, not C. It
can be used to wrap C libraries but for sure there are better and simpler
tools to do that.
--
On Thursday 15 December 2011 19:06:31 anatoly techtonik wrote:Historic reasons, besides the fact that the C++ parser we have was written in
> Can anybody help me? I am really stuck.
>
> I can't understand why C++ was chosen to write the tool like Shiboken. If
> it was in Python - it was much more easier to troubleshoot the issues like
> this one.
C++. I already tried to create bindings for ApiExtractor (where the C++ parser
lives) using the current Shiboken and rewrite the generator in Python, but
it's a lot of work and I had no free time to do that so I forgot this idea.
As I said Shiboken was intended to be used to wrap C++ libraries, not C. It
can be used to wrap C libraries but for sure there are better and simpler
tools to do that.
Anatoly,
if you ran Shiboken with your type system file it will issue a warning
telling that it couldn't find your function:
Global function 'int avbin_get_version()' is specified in typesystem,
but not defined. This could potentially lead to compilation errors.
That's because you should not write the return value in the signature,
so this will do:
<function signature='avbin_get_version(void)' />
It will still not work if you don't add a line to declare that you
will be using an integer as primitive type, so add this too:
<primitive-type name='int'/>
It will generate the file "out/AVbin/avbin_module_wrapper.cpp" with
the wrapper for your function.
Cheers,
Marcelo