Ask Your Question
0

Linking error when building OpenCV 3.2.0 with Python support

asked 2017-03-08 06:43:07 -0600

adn gravatar image

updated 2017-03-08 13:17:22 -0600

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.

edit retag flag offensive close merge delete

Comments

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?

adn gravatar imageadn ( 2017-03-08 13:53:32 -0600 )edit

Not sure if this is relevant but what does ldd cv2.so give you, any missing dependencies?

Kerry gravatar imageKerry ( 2017-03-10 19:29:09 -0600 )edit

I have same specification and had same problem try manually copying cv2.so, as given in FAQ of http://www.pyimagesearch.com/2016/10/... .

manJ gravatar imagemanJ ( 2017-05-16 01:59:24 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-03-15 16:41:59 -0600

adn gravatar image

Is not entirely a solution for the 3.2.0 tag, but by changing the branch to 3.2.0-rc it was solved.

Probably there are some extra configuration on the normal branch that is not straightforward to get.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2017-03-08 06:43:07 -0600

Seen: 2,837 times

Last updated: Mar 15 '17