I'm an extension noob. What I want to do is create an extension that doesn't require other libraries to be installed. Is this impossible because the extension has to link against a specific version of libpython at runtime?
Static libraries, while reusable in multiple programs, are locked into a program at compile time. Dynamic, or shared libraries, on the other hand, exist as separate files outside of the executable file.
The most significant advantage of shared libraries is that there is only one copy of code loaded in memory, no matter how many processes are using the library. For static libraries each process gets its own copy of the code. This can lead to significant memory wastage.
To create such a library, the exported functions/procedures and other objects variables must be specified for external linkage (i.e. by not using the C static keyword). Static library filenames usually have ". a" extension on Unix-like systems and " . lib" extension on Microsoft Windows.
You can't do this. You have two options: Recompile the library as a shared library. Then use ctypes to call methods from the dynamically-loaded shared library.
You can't make a statically linked extension module because Python needs to load it dynamically at runtime and because (as you reasoned) the module needs to dynamically link against libpython.
You could compile your own custom version of Python with your extension statically linked into the interpreter. That's usually more trouble than it's worth.
Why do you want to make a statically linked extension? If we have more information about your goals, we might be able to help you achieve them in a different way.
Welcome to StackOverflow. :-)
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