Shared Objects in Python ======================== ctypes is a foreign function library for Python. It provides C compatible data types, and allows calling functions in DLLs or shared libraries. It can be used to wrap these libraries in pure Python. Eine Einfache Library --------------------- First let us write a small c-library, a simple Hello-World example is sufficient: .. code-block:: c #include void myprint(void); void myprint() { printf("Hello World\n"); } Now, compile it as a shared library: .. code:: bash $ gcc -shared -Wl,-soname,testlib -o testlib.so -fPIC testlib.c Zugriff auf Shared Objects -------------------------- In Python, write a wrapper using ctypes: .. code-block:: python import ctypes testlib = ctypes.CDLL("testlib.so") testlib.myprint() and execute it like this: .. code:: bash $ python cwrapper.py You should see the following output: .. code:: bash % python cwrapper.py Hello World