The count of programming languages approaches infinity, and a huge chunk of them have a C interface. This short chapter offers some general notes about the process and demonstrates in detail the interface with one language, Python.
Every language has its own customs for packaging and distribution, which means that after you write the bridge code in C and the host language, you get to face the task of getting the packaging system to compile and link everything. This gives me a chance to present more advanced features of Autotools, such as conditionally processing a subdirectory and adding install hooks.
Before jumping into other languages, it is worth taking a moment to appreciate the C functions that make it all possible:
dlsym. These functions open a dynamic library and extract a symbol, such as a static object or a function, from that library.
The functions are part of the POSIX standard. Windows systems have a similar setup, but the functions are named
GetProcAddress; for simplicity of exposition, I’ll stick to the POSIX names.
The name “shared object file” is nicely descriptive: such a file includes a list of objects, including functions and statically defined structures, that are intended for use in other programs.
Using such a file is much like retrieving an item from a text file holding a list of items. For the text file, you would first call
fopen to get a handle for the file, and then call ...