4

I am trying to install OpenCV3.1 on my Ubuntu 16.04 for development in QT5. Sadly, building it from source always errors out due to undefined references (see below).

I used the following:

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D WITH_V4L=ON -D WITH_FFMPEG=ON -D WITH_OPENGL=ON -D BUILD_TIFF=ON -D WITH_VTK=ON..

And it works fine. But building it always produces this error

../../lib/libopencv_viz.so.3.1.0: undefined reference to `vtkSTLReader::New()'
../../lib/libopencv_viz.so.3.1.0: undefined reference to `vtkOBJReader::New()'
collect2: error: ld returned 1 exit status
modules/viz/CMakeFiles/opencv_test_viz.dir/build.make:232: recipe for target 'bin/opencv_test_viz' failed
make[2]: *** [bin/opencv_test_viz] Error 1
CMakeFiles/Makefile2:3358: recipe for target 'modules/viz/CMakeFiles/opencv_test_viz.dir/all' failed
make[1]: *** [modules/viz/CMakeFiles/opencv_test_viz.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....

Of course I googled and tried everything I found. Tried several different cmake flags (or rather, without any), tried reinstalling libvtk5-dev and also tried libvtk6-dev and even build vtk7.1 from source, since I am assuming something is missing from there.

I also tried adding the opencv_contrib via

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D WITH_V4L=ON -D WITH_FFMPEG=ON -D WITH_OPENGL=ON -D BUILD_TIFF=ON -D WITH_VTK=ON -D BUILD_EXAMPLES=ON -D OPENCV_EXTRA_MODULES_PATH=/home/user/opencv/opencv-3.1.0/opencv_contrib/modules ..

But that already produced the following error

CMake Error at opencv_contrib/modules/text/CMakeLists.txt:22 (ocv_add_testdata): `Unknown CMake command "ocv_add_testdata".

Also please note that I did upgrade/update all the packages that are listed here and here

So basically after two days randomly trying all the possible solutions I could find via google, I am now asking here. Hopefully someone knows how to fix this, thank you!

Edit: I only get these problems with OpenCV3.1. I do have a working OpenCV 2.4.13

Blueberry
  • 41
  • 1
  • 3
  • The problems seems to be with VTK, which does not appear in the links of packages that you posted. Can you build with `-D WITH_VTK=OFF`, or install vtk?. P.S compiling with `QT` and `VTK` at the same time might result in complications: http://answers.opencv.org/question/61773/vtk-support-disabled-due-to-incompatible-opencvvtkqt-combination/ – Morris Franken Dec 06 '16 at 16:51

4 Answers4

0

Same happend with me. It was working and suddenly I got the same error. I re-pulled OpenCV 3.1 and it worked again.

It seems that the guys updated something both in Extra Modules and in OpenCV and you have just pull the extra modules.

Humam Helfawi
  • 19,566
  • 15
  • 85
  • 160
0

For the second part, it looks like someone messed up the opencv_contrib/modules/text/CMakeLists.txt

Just edit this file and remove the lines at the end:

ocv_add_testdata(samples/ contrib/text
    FILES_MATCHING PATTERN "*.xml" PATTERN "*.xml.gz" REGEX "scenetext[0-9]+.jpg"
    COMPONENT "tests"
)
Peter
  • 8,776
  • 6
  • 62
  • 95
Ben
  • 1
  • I did what you said, seems to be working for me. BTW, will it have any effect afterwards? i mean, will my contrib modules work fine after this edit? – jAYANT YADAV Dec 19 '16 at 04:00
0

just switch opencv_contrib repository to 3.1.0 tag after clone.

git checkout 3.1.0

and try to build again.

0

First, make sure you have successfully built and installed vtk on your system;

Then,by using command "locate STLReader" or "locate vtkOBJReader" to ensure "vtkOBJReader" or "STLReader" libs are found in some specific directories. If vtkOBJReader or STLReader related files are found. It means that vtk has changed its structure in the new version, e.g. move vtkOBJReader into a sub library vtkIOGeometry, so you have to tell cmake to find vtkIOGeometry if you want to use that class.

Last, modify opencv3/cmake/OpenCVDetectVTK.cmake, for every find_package(VTK QUIET COMPONENTS ... add an entry vtkIOGeometry.

Success!

oceanblue
  • 1
  • 2