Linking error when building OpenCV 3.2.0 with Python support
I build OpenCV 3.2.0 from the sources (including the contrib modules) using the 3.2.0
branch. And when I import it within python, through import cv2
, I get an undefined symbol
error. That in my experience seems like a linking error.
$ python
Python 2.7.12+ (default, Sep 17 2016, 12:08:02)
[GCC 6.2.0 20160914] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: /usr/local/lib/python2.7/dist-packages/cv2.so: undefined symbol: _Z13pyopencv_fromIN2cv4MatxIdLi4ELi4EEEEP7_objectRKT_
>>>
$ python3
Python 3.5.2+ (default, Sep 22 2016, 12:18:14)
[GCC 6.2.0 20160927] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: /usr/local/lib/python3.5/dist-packages/cv2.cpython-35m-x86_64-linux-gnu.so: undefined symbol: _Z13pyopencv_fromIN2cv4MatxIdLi4ELi4EEEEP7_objectRKT_
>>>
My gcc
$ gcc --version
gcc (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
My flags in cmake
are as follows:
cmake \
-D CMAKE_BUILD_TYPE=RELEASE \
-D ENABLE_PRECOMPILED_HEADERS=OFF \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
-D BUILD_NEW_PYTHON_SUPPORT=ON \
-D WITH_TBB=ON \
-D WITH_QT=ON \
-D WITH_OPENGL=ON \
-D BUILD_TIFF=ON \
-D BUILD_SHARED_LIBS=OFF \
-D BUILD_EXAMPLES=ON \
..
I see in other posts that the problem my be due to the sharing libraries, and so I tried with -D BUILD_SHARED_LIBS=OFF
but that doesn't work either. My system is
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.10
Release: 16.10
Codename: yakkety
Let me know if you need more information. Any help is appreciated.
Is this related to this other problem http://stackoverflow.com/questions/11643666/python-importerror-undefined-symbol-for-custom-c-module (http://stackoverflow.com/questions/11...) Maybe the order in the
Makefile
that links the libraries?Not sure if this is relevant but what does
ldd cv2.so
give you, any missing dependencies?I have same specification and had same problem try manually copying cv2.so, as given in FAQ of http://www.pyimagesearch.com/2016/10/... .