C++ extension and shared library with distutils

Wintersberger, Eugen eugen.wintersberger at desy.de
Tue Oct 28 12:09:27 CET 2014


Hi folks
  I have a little problem with a Python extension and could not find a
good solution in the documentation. So hopefully someone here has a
clever idea. 

Here is the problem: I have two extensions written in C++ (bindings to
existing C++ code). Lets call this two extensions C and B which are part
of a larger package with parent A. So in the simplest case the
installation on Linux would somehow look like this
A/
  __init__.py
  B/
   __init__.py
   _b.so
  C/
   __init__.py
   _c.so

The extension C is optional but depends on B. In the code for C I would
like to use some utilities developed for B. The idea was to keep this
utility functions in a shared library and link B and C against this
library. Lets call this library libb_utils.so. The problem here is that
the code in libb_utils.so depends on the Python version used to build
the extensions so it is not possible to build a Python agnostic version
of the library. 

My idea now was to build extension B and in the same code tree build
libb_utils.so. The idea was to install this shared object along with the
extension and then link C against it. The new installation would look
like this

A/
  __init__.py
  B/ 
   __init__.py
   _b.so
   libb_utils.so

with header files for libb_utils.so in 

$PREFIX/include/pythonX.Y/A/B/

My hope is that I can do all this with distutils. Building and
installing the extension is trivial. But

1.) is there a better way to build a shared library with distutils
    than using the CCompiler submodule?
2.) is the way I am planning the installation of my code ok 
    or is there a better way (maybe even a kind of standard) to deal
    with such a situation. 

best regards and thanks in advance
  Eugen Wintersberger

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 230 bytes
Desc: This is a digitally signed message part
URL: <http://mail.python.org/pipermail/python-list/attachments/20141028/cc400db8/attachment.sig>


More information about the Python-list mailing list