ctypes Usage Note

Lawrence D’Oliveiro lawrencedo99 at gmail.com
Mon Aug 1 21:41:53 EDT 2016


Sometimes people load a library with ctypes like this:

    libc = ctypes.cdll.LoadLibrary("libc.so")

Don’t do that. Do this instead:

    libc = ctypes.cdll.LoadLibrary("libc.so.6")

What’s the difference? The difference is that the unversioned library comes from the “development” package, while the versioned one comes from the “runtime” package. Users of your Python binding should only need to have the runtime package installed to run scripts that use it, not the development package.

So: always load the explicitly-versioned library name.

I thnk this recommendation should be part of the official ctypes docs <https://docs.python.org/3/library/ctypes.html>, don’t you?



More information about the Python-list mailing list