Hi Everyone,
I'm considering about generating some Python Bindings for C++
libraries. What are considered the best tools for doing something like
this? I know that there are SWIG, SIP, Boost.Python, and GCC_XML.
Thanks! 9 1891 br******@gmail. com wrote:
I'm considering about generating some Python Bindings for C++
libraries. What are considered the best tools for doing something
like this? I know that there are SWIG, SIP, Boost.Python, and
GCC_XML.
Please excuse me for asking the following stupid question ...
I'm planning to buy a car. What is the best brand? I know that there
are Mercedes, Opel, Honda and Ford.
Regards,
Björn
P.S.: Try this googled link and look for the comparation paragraph,
in section "Introducti on": http://www.boost-consulting.com/writing/bpl.html
--
BOFH excuse #163:
no "any" key on keyboard
On Mar 9, 7:04 am, "bress...@gmail .com" <bress...@gmail .comwrote:
Hi Everyone,
I'm considering about generating some Python Bindings for C++
libraries. What are considered the best tools for doing something like
this? I know that there are SWIG, SIP, Boost.Python, and GCC_XML.
Thanks!
Declare the functions you want to use in Python with 'extern "C"', and
make them available in a dynamic library. Then use ctypes to call them
directly.
Regards,
Willard
8 Mar 2007 22:04:48 -0800 skrev br******@gmail. com:
Hi Everyone,
I'm considering about generating some Python Bindings for C++
libraries. What are considered the best tools for doing something like
this? I know that there are SWIG, SIP, Boost.Python, and GCC_XML.
We are doing this quite extensively at work, and have found that in the
long run SWIG is the best solution. OMMV, but if you ask me, the answer
is SWIG.
mvh,
--
Mandus - the only mandus around.
Mandus wrote:
8 Mar 2007 22:04:48 -0800 skrev br******@gmail. com:
>Hi Everyone,
I'm considering about generating some Python Bindings for C++ libraries. What are considered the best tools for doing something like this? I know that there are SWIG, SIP, Boost.Python, and GCC_XML.
We are doing this quite extensively at work, and have found that in the
long run SWIG is the best solution. OMMV, but if you ask me, the answer
is SWIG.
mvh,
--
Mandus - the only mandus around.
Hi,
Why do you think it is better than ctypes ?
Thanks,
hg
En Fri, 09 Mar 2007 05:28:54 -0300, hg <hg@nospam.orge scribió:
Mandus wrote:
>8 Mar 2007 22:04:48 -0800 skrev br******@gmail. com:
>>I'm considering about generating some Python Bindings for C++ libraries. What are considered the best tools for doing something like this? I know that there are SWIG, SIP, Boost.Python, and GCC_XML.
We are doing this quite extensively at work, and have found that in the long run SWIG is the best solution. OMMV, but if you ask me, the answer is SWIG.
Why do you think it is better than ctypes ?
I won't say SWIG is better than anything, but how would you use ctypes to
create an instance of a class with several levels of inheritance, and then
invoke a virtual method?
You have to mangle all the names (not too bad, can be done in Python
following the rules) but you also need to find the right function pointer
in the virtual method table; and that can't be done without processing the
source code (at least the .h) in order to know the layout and ordering of
the methods.
Let alone inline functions, templates and #define macros.
--
Gabriel Genellina
Gabriel Genellina wrote:
En Fri, 09 Mar 2007 05:28:54 -0300, hg <hg@nospam.orge scribió:
>Mandus wrote:
>>8 Mar 2007 22:04:48 -0800 skrev br******@gmail. com: I'm considering about generating some Python Bindings for C++ libraries. What are considered the best tools for doing something like this? I know that there are SWIG, SIP, Boost.Python, and GCC_XML.
We are doing this quite extensively at work, and have found that in the long run SWIG is the best solution. OMMV, but if you ask me, the answer is SWIG.
Why do you think it is better than ctypes ?
I won't say SWIG is better than anything, but how would you use ctypes to
create an instance of a class with several levels of inheritance, and then
invoke a virtual method?
You have to mangle all the names (not too bad, can be done in Python
following the rules) but you also need to find the right function pointer
in the virtual method table; and that can't be done without processing the
source code (at least the .h) in order to know the layout and ordering of
the methods.
Let alone inline functions, templates and #define macros.
--
Gabriel Genellina
I'm not very familiar with the technology as I just have had to modify an
extension here and there.
I guess my question is off topic as a C++ dll / shared lib is not my main
target but rather C: I need to integrate a printer driver and and would
like if possible to avoid all of the .h stuff involved with SWIG (I am not
being sarcastic): if I can setup my prototypes directly in python, why go
through an extra layer ?
Aren't ctypes better suited to such an application ?
hg
En Fri, 09 Mar 2007 18:16:43 -0300, hg <hg@nospam.orge scribió:
I'm not very familiar with the technology as I just have had to modify an
extension here and there.
I guess my question is off topic as a C++ dll / shared lib is not my main
target but rather C: I need to integrate a printer driver and and would
like if possible to avoid all of the .h stuff involved with SWIG (I am
not
being sarcastic): if I can setup my prototypes directly in python, why go
through an extra layer ?
Aren't ctypes better suited to such an application ?
Sure, if you have a C (not C++) DLL, using ctypes should be OK.
--
Gabriel Genellina
hg <hg@nospam.orgw rote:
...
target but rather C: I need to integrate a printer driver and and would
like if possible to avoid all of the .h stuff involved with SWIG (I am not
being sarcastic): if I can setup my prototypes directly in python, why go
through an extra layer ?
Aren't ctypes better suited to such an application ?
One advantage of solutions generating C code that gets compiled (SWIG,
Pyrex, writing C-API code directly, etc) is that the C compiler can warn
you, or produce compile-time mistakes, for many kinds of programming
errors; with ctypes, you will instead be finding every such error at
runtime, each time by noticing that Python crashed and facing a
substantial amount of debugging and code inspection to find out why.
Alex
Alex Martelli schrieb:
hg <hg@nospam.orgw rote:
...
>target but rather C: I need to integrate a printer driver and and would like if possible to avoid all of the .h stuff involved with SWIG (I am not being sarcastic): if I can setup my prototypes directly in python, why go through an extra layer ?
Aren't ctypes better suited to such an application ?
One advantage of solutions generating C code that gets compiled (SWIG,
Pyrex, writing C-API code directly, etc) is that the C compiler can warn
you, or produce compile-time mistakes, for many kinds of programming
errors; with ctypes, you will instead be finding every such error at
runtime, each time by noticing that Python crashed and facing a
substantial amount of debugging and code inspection to find out why.
In principle this is true, some points however I would like to point out:
- The ctypes codegenerator, based on GCCXML, is in a pretty good shape.
A lot of boilerplate (Python) code can be generated automatically.
The codegenerator is available from CVS, with 'easy_install ctypeslib'.
GCCXML has to be installed separately.
- Not always does Python crash on programming errors. On windows, calls
to foreign functions are 'protected' by windows structured exception
handling. In other words, most of the time you get a Python traceback
instead of a segfault.
- There are some large libraries and also smaller ones that are already
wrapped with ctypes. PyOpenGL is probably the most promiment example,
comtypes (although still in heavy development) another one.
As the ctypes author I'm of course biased.
Thomas This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
| |
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |