I want to use a C++ library from Python

A

Anders Eriksson

Hello,

I have a C++ library compiled as Windows DLL's. It consists of 32 .h and 1
..lib and 1 .dll files. I don't have the source code.

How can I create a Python module from these files?

// Anders
 
D

Diez B. Roggisch

kaer said:
You may want google "python dll" as well. Good luck.

Which actually isn't really helpful, as a DLL itself says nothing about what
language was used to create it - and sending the OP to e.g. ctypes makes no
sense at all in the face of C++.

Whereas the first link for "python c++" is Boost::python, a C++-wrapper to
make C++-code accessible from Python.

Diez
 
A

Anders Eriksson

Hello all and thanks for replying,

The library - or more precisely the calling convention of the library -
is related to the solution. On Windows a dll might be a container for a
.NET assembly and C++ code can (theoretically) be compiled to .NET, too.
No, the library is not an .NET assembly. It's an VC++ Library compiled as
an Dll.
C++ bindings can be created with SIP, SWIG, Boost or hand written code.
Multiple sites claim that SIP generates the fastest code.
I have looked (very briefly) at the three framework you mention but they
all need the source code of the C++?

I don't have the source code! Just the header files and the library and
dll.

Have I overlooked something or am I just screwed?

// Anders
 
F

Fredrik Lundh

Anders said:
I have looked (very briefly) at the three framework you mention but they
all need the source code of the C++?

No, they need header files and an import library to be able to compile
the bindings and link them to your DLL.

Do you know enough about C/C++ build issues to be able to compile a C++
program against the given library? If you do, fixing the rest should be
straightforward, since the binding is just another C++ program designed
to be imported by Python.

</F>
 
U

Uwe Schmitt

Hello,

I have a C++ library compiled as Windows DLL's. It consists of 32 .h and 1
.lib and 1 .dll files. I don't have the source code.

How can I create a Python module from these files?

Do you need the full library including classes or just some
functions ?
You could write a wrapper in C around the lib and use f2py or ctypes
to call your wrapper from python.
But that does not work if you want to expose classes.

Greetings, Uwe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top