473,385 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

I want to use a C++ library from Python

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
--
English is not my first, or second, language
so anything strange, or insulting, is due to
the translation.
Please correct me so I may improve my English!
Sep 10 '08 #1
7 1345
Anders Eriksson schrieb:
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?
Did you bother googling?

http://www.google.de/search?q=python...utf-8&oe=utf-8

Diez
Sep 10 '08 #2
On 10 sep, 10:00, "Diez B. Roggisch" <de...@nospam.web.dewrote:
Anders Eriksson schrieb:
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?

Did you bother googling?

http://www.google.de/search?q=python...utf-8&oe=utf-8

Diez
You may want google "python dll" as well. Good luck.
Sep 10 '08 #3
kaer wrote:
On 10 sep, 10:00, "Diez B. Roggisch" <de...@nospam.web.dewrote:
>Anders Eriksson schrieb:
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?

Did you bother googling?

http://www.google.de/search?q=python...utf-8&oe=utf-8

Diez

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
Sep 10 '08 #4
Diez B. Roggisch wrote:
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++.
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.
Whereas the first link for "python c++" is Boost::Python, a C++-wrapper to
make C++-code accessible from Python.
C++ bindings can be created with SIP, SWIG, Boost or hand written code.
Multiple sites claim that SIP generates the fastest code.

Christian

Sep 10 '08 #5
Hello all and thanks for replying,

Diez B. Roggisch wrote:
>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++.

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.
>Whereas the first link for "python c++" is Boost::Python, a C++-wrapper to
make C++-code accessible from Python.

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
--
English is not my first, or second, language
so anything strange, or insulting, is due to
the translation.
Please correct me so I may improve my English!
Sep 11 '08 #6
Anders Eriksson wrote:
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>

Sep 11 '08 #7
On 10 Sep., 09:57, Anders Eriksson <andi...@gmail.comwrote:
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
Sep 11 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mark McEahern | last post by:
I just wrote a very simple wrapper for the PayFlow Pro SDK (see below). A friend of mine did this before, but I didn't have access to his source, so I took it as a learning opportunity for me to...
1
by: Ajay Brar | last post by:
hi! i am new to python. i am looking for a library/package that implements public key encryption. on the python library reference page, it mentins hmac, md5, sha, mpz and rotor under...
6
by: Hung ho | last post by:
Hi. I just finished reading an introductory Python book called "Python Programming for the absolute beginner" by Michael Dawson. I found it very interesting, and easy to follow. Python does really...
13
by: Roy Smith | last post by:
I've got a C library with about 50 calls in it that I want to wrap in Python. I know I could use some tool like SWIG, but that will give me a too-literal translation; I want to make some...
18
by: Cameron Laird | last post by:
QOTW: "... So I started profiling the code and the slowdown was actually taking place at places where I didn't expect it." -- Guyon Mor?e (and about twenty-three thousand others) " suggestion...
10
by: mwt | last post by:
So in a further attempt to learn some Python, I've taken the little Library program (http://groups.google.com/group/comp.lang.python/browse_thread/thread/f6a9ccf1bc136f84) I wrote and added...
5
by: sophie_newbie | last post by:
OK this might seem like a retarded question, but what is the difference between a library and a module? If I do: import string am I importing a module or a library? And if i do...
2
by: mirandacascade | last post by:
I am prompted to make these inquiries after seeing the following link to ctypes: http://docs.python.org/lib/module-ctypes.html in which ctypes is described as a foreign function library. ...
3
by: Martin Evans | last post by:
I have converted a Python script using py2exe and have it set to not bundle or compress. The result is my exe and all the support files including library.zip (exactly as planned - nice job py2exe)....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.