Search code examples
python-c-extension

calling legacy c functions from python


I want to call legacy c third party functions from python. I created a C api to make the function calls simpler. In my python file I tried to import the *.so for the api which links with the legacy code library. But I kept seeing a libxxx ( the legacy c library) not found error. I tried to import both ans still saw the same error. I then tried using ctypes, but get the error ctypes not found. Any suggestions ?

# python
Python 2.4.2 (#1, Apr 20 2012, 19:31:49)
[GCC 4.1.2 20070115 (SUSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ImportError: No module named ctypes
>>> quit

Solution

  • ctypes only made it into the standard library in version 2.5, so 2.4 does not have it. I've also heard that some people exclude it when they build Python for a distribution or for embedding in a specific application, as you can easily crash your process using it, or even corrupt the host application's heap. But I have never encountered this myself, and I doubt a full installation does this.

    As for not finding your C library, we'll need more details on that.