I've written Python bindings using ctypes for the units library. The bindings themselves are only ~100 lines of Python. The library has an unnecessary (for the purposes of the Python bindings) dependency on tcl, and the configure script fails if tcl is absent. However, the library builds fine with gcc -Wl,-soname,units.so -o units.so -fPIC -shared units.c
.
I would now like to release these bindings. There are three ways I could do this.
If I choose option 2, where should I put the library? Should I put it in the same directory as the .py file, allowing me to assume lib_name = CDLL('./units.extension')
, or should I put it in a directory that tends to be in the linker's path (like /lib)? In addition, how is this normally handled for Windows machines which a) might not have a C compiler and b) have no standard place to put shared libraries?
Which of these options is the preferred one and what should I do about the Windows case?
It appears that the units
library hasn't been modified in over 5 years, so option 2 may be the best one. It's also unlikely that one of the major distributions will package it (I can't find it in Ubuntu Lucid or Macports for example).
For example, copy units.c and units.h into your project and create a setup.py to compile and deploy it along with your bindings:
from setuptools import setup, Extension
sources = ['src/units.c']
ext_opts = {'extra_compile_args': ['-Wl,-soname,units.so', '-Isrc']}
setup(
name='units',
ext_modules = [Extension('units', sources, **ext_opts)]
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With