I’ve statically linked a python interpretter (libpython.a
) into a C++ program.
When I try to use it to import a python module that contains a native dynamic library component (a .so
), I get an error that the core python library symbols are unavailable.
For example, if I try to:
import subprocess
I get:
ImportError: _posixsubprocess.so: undefined symbol: PyTuple_Type
Likewise, if I try:
import ctypes
I get:
ImportError: _ctypes.so: undefined symbol: PyFloat_Type
These two functions PyTuple_Type
and PyFloat_Type
are part of the core python library (libpython.a
), so should be statically linked into the program.
Yet, when these dynamic libraries (_posixsubprocess.so
or _ctypes.so
) are loaded, they can’t seem to find them.
Any ideas?
In general, when you load a dynamic library can its needed undefined external symbols be resolved by symbols that are statically defined/linked in the main program? I’m not sure I understand how that works (or if it’s supposed to work).
The relevant parts of the test program are:
#include <Python.h>
int main() {
Py_Initialize();
PyRun_SimpleString("import subprocess")
}