我正在编写一个使用(包装)外部C ++库的CPython模块,我写了一个setup.py
包含:
from distutils.core import setup, Extension
# define the extension module
my_ext = Extension("_my_ext",
sources=["src/my_ext.cpp"],
include_dirs=["src/include"],
extra_link_args=["-fPIC"],
language="c++",
libraries=["~/path/to/external/lib/xxx.so"],
extra_objects=["~/path/to/external/lib/xxx.so"])
# run the setup
setup(ext_modules=[my_ext])
扩展编译成功:
$ python setup.py build_ext --include-dirs=~/path/to/external/lib1/:~/path/to/external/lib2/
running build_ext
但是导入模块时会出现以下错误:
$ » python -c "import _my_ext"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: ./_my_ext.so: undefined symbol:
_ZN10my_lib6system16my_lib_functionEPKc
我的猜测是在链接过程中,对吧?