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. The error appears simply when I add the lib to my setup.py file. 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:
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. Before adding this lib to my shared library, everything was working perfectly.
Thanks to the comments of abarnert, I solved the problem updating and upgrading MacPorts. As abarnert observed, there was a linking problem between /opt/local/lib/libXext.6.dylib
and /opt/local/lib/libX11.6.dylib
.
So I did:
$ sudo port selfupdate
$ sudo port upgrade outdated