添加到setup.py文件时,动态库会导致错误(在Mac OS.X上)

时间:2013-08-26 17:46:51

标签: c++ python opencv cython distutils

我有一个动态库,用cpp构建,实际上在cpp中工作但是当我尝试从python类导入它时会引起很多麻烦。当我将lib添加到我的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

Setup.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库。在将此lib添加到我的共享库之前,一切都运行良好。

  • 如何找出导致错误的原因?
  • 我应该尝试使用静态库而不是动态库吗?
  • P.S。:我的 DYLD_LIBRARY_PATH =〜/ Projects / CppOpenCV / python_cpp_interface / source /:/ usr / local / mysql / lib /

1 个答案:

答案 0 :(得分:0)

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

所以我做了:

$ sudo port selfupdate
$ sudo port upgrade outdated
相关问题