我有一个动态库,内置在 cpp 中,实际上可以在 cpp 中工作,但是当我尝试从 python 类中导入它时会引起很多头痛。当我将库添加到我的 setup.py 文件时,就会出现错误。错误:
MacBook-Pro-de-Marcelo-Salloum:python_cpp_interface marcelosalloum$ python userect.py
Traceback (most recent call last):
File "userect.py", line 2, in <module>
from rectangle import Rectangle
ImportError: dlopen(/Users/marcelosalloum/Projects/CppOpenCV/python_cpp_interface/rectangle.so, 2): Symbol not found: __XEatDataWords
Referenced from: /opt/local/lib/libXext.6.dylib
Expected in: /opt/local/lib/libX11.6.dylib
in /opt/local/lib/libXext.6.dylib
安装程序.py:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
setup(
name = 'DyCppInterface',
version = '1.0',
author = 'Marcelo Salloum dos Santos',
# The ext modules interface the cpp code with the python one:
ext_modules=[
Extension("rectangle",
sources=["rectangle.pyx", "cpp_rect.cpp"], # Note, you can link against a c++ library instead of including the source
include_dirs=[".","source", "/opt/local/include/opencv", "/opt/local/include"],
language="c++",
# extra_link_args = ['-arch x86_64'],
# extra_link_args = ['-arch i386', '-arch x86_64'],
library_dirs=['/usr/local/lib', 'source'],
runtime_library_dirs=['/Users/marcelosalloum/Projects/CppOpenCV/python_cpp_interface/source'],
libraries=['LibCppOpenCV'])
],
cmdclass = {'build_ext': build_ext},
)
众所周知,这个 *.so 文件使用了一个 c++ OpenCV 库。在将此库添加到我的共享库之前,一切正常。
- 如何找出导致错误的原因?
- 我应该尝试使用静态库而不是动态库吗?
- PS:我的DYLD_LIBRARY_PATH = ~/Projects/CppOpenCV/python_cpp_interface/source/:/usr/local/mysql/lib/