简体   繁体   English

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

[英]Dynamic Library causes error when added to setup.py file (on Mac OS.X)

I have a dynamic library, built in cpp that actually works in cpp but is causing much headache when I try to import it from a python class. 我有一个内置于cpp中的动态库,该库实际上可以在cpp中工作,但是当我尝试从python类导入它时却引起很多麻烦。 The error appears simply when I add the lib to my setup.py file. 仅当我将lib添加到setup.py文件时,该错误才会出现。 Error: 错误:

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: 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},
)

It is known that This *.so file uses a c++ OpenCV library. 众所周知,此* .so文件使用c ++ OpenCV库。 Before adding this lib to my shared library, everything was working perfectly. 在将此库添加到我的共享库之前,一切工作正常。

  • How to figure out what is causing the error? 如何找出导致错误的原因?
  • Should I try with a static library instead of a dynamic one? 我应该尝试使用静态库而不是动态库吗?
  • PS: my DYLD_LIBRARY_PATH = ~/Projects/CppOpenCV/python_cpp_interface/source/:/usr/local/mysql/lib/ PS:我的DYLD_LIBRARY_PATH =〜/ Projects / CppOpenCV / python_cpp_interface / source /:/ usr / local / mysql / lib /

Thanks to the comments of abarnert, I solved the problem updating and upgrading MacPorts. 感谢abarnert的评论,我解决了更新和升级MacPorts的问题。 As abarnert observed, there was a linking problem between /opt/local/lib/libXext.6.dylib and /opt/local/lib/libX11.6.dylib . 正如abarnert所观察到的,/ /opt/local/lib/libXext.6.dylib / /opt/local/lib/libX11.6.dylib /opt/local/lib/libXext.6.dylib/opt/local/lib/libX11.6.dylib之间存在链接问题。

So I did: 所以我做了:

$ sudo port selfupdate
$ sudo port upgrade outdated

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM