I tried to reproduce this and got two different error messages 'like undefined symbol'. I'll explain both since I'm not 100% sure which one you encountered.
this first was:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: /mnt/tmpfs/py.so: undefined symbol: _ZNK5boost6python7objects21py_function_impl_base9max_arityEv
the undefined symbol here is a mangled c++ name boost::python::objects::py_function_impl_base::max_arity() const
wich can be found in libboost_python39.so for example. This means you have to link your library with -lboost_python39
to make this symbol available.
the second was:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define module export function (PyInit_py)
This one went away when I gave library file the module name that is mentioned in the source code modd.so
. I have never used boost_python before so I can't guarantee that this is in fact what the error means.
TL;TR
I got it working by changing the second build line to
g++ -shared -o modd.so py.o -lboost_python39
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…