0

我有一个动态库,内置在 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/
4

1 回答 1

0

感谢 abarnert 的评论,我解决了更新和升级 MacPorts 的问题。正如 abarnert 所观察到的,/opt/local/lib/libXext.6.dylib和之间存在链接问题/opt/local/lib/libX11.6.dylib

所以我做了:

$ sudo port selfupdate
$ sudo port upgrade outdated
于 2013-08-26T20:13:39.157 回答