I've been trying all week to build OpenCV 3.1.0 from sourcefor Python3.5 and Python2.7 on my local computer (Ubuntu 15.04 Vivid 64-bit), since there does not appear to be a compatible version available through aptitude. However, FFMPEG and libav are the impasses I cannot solve - several other issues with not finding HDF5 or Eigen3 I was able to fix relatively easily. Some of the tutorials and lessons I want to do use video as input, so I need to be the video tools working for OpenCV. I have been able to build OpenCV 3.1.0 successfully using the option WITH_FFMPEG=OFF
and confirmed I could import cv2
and use all of its non-video functions without a problem. I have tried installing ffmpeg and the libav dev libraries using aptitude as well as building FFMPEG from source. For the messages below, I'm using the FFMPEG I built myself.
The error I get is the following after calling make
in the ~/github/opencv/build
directory:
make[2]: *** No rule to make target `/home/grant/github/ffmpeg/libavcodec.a`, needed by 'lib/libopencv_videoio.so.3.1.0'. Stop.
CMakeFiles/Makefile2:6038: recipe for target 'modules/videoio/CMakeFiles/opencv_videoio.dir/all' failed
make[1]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/all] Error 2
Makefile:147: recipe for target 'all' failed
make: *** [all] Error 2
This is the error I want to solve. The rest of this post provides more information on what I've done and my setup. Note that FFMPEG I built from source (as well as libavcodec, libavfilter, libavutils, etc.) is in the ~/github/ffmpeg
directory.
When looking up this error, the most common suggestions involved static libraries and shared objects, namely that ffmpeg needed to be compiled with --enable-shared
and --disable-static
for the opencv build to work. This is why I built FFMPEG from source. Here's the output when I call ./ffmpeg
from the appropriate directory, confirming it was built with those options enabled: see the configuration
line.
ffmpeg version N-80096-gdefab08 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 4.9.2 (Ubuntu 4.9.2-10ubuntu13)
configuration: --enable-shared --disable-static
libavutil 55. 24.100 / 55. 24.100
libavcodec 57. 43.100 / 57. 43.100
libavformat 57. 37.100 / 57. 37.100
libavdevice 57. 0.101 / 57. 0.101
libavfilter 6. 46.100 / 6. 46.100
libswscale 4. 1.100 / 4. 1.100
libswresample 2. 0.101 / 2. 0.101
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
The subdirectories libavcodec
, libavfilter
, libavutil
, libavformat
, libavdevice
, libswscale
, and libswresample
are all in the aforementioned ~/github/ffmpeg
directory. Each of those contains the .so
shared object file created by make
, which I think is what I should be using to build OpenCV, but it seems to be looking for static .a
files (e.g. libavcodec.a
), which is in my /usr/lib/x86_64-linux-gnu/
directory. I HAVE tried pointing the FFMPEG_LIB_DIR
option to this directory, but this just throws the same error at the same point in compilation. This is what also led me to building FFMPEG with the --enable-shared
and --disable-static
options. Should I instead enable static so that make
creates the .a
files?
Additionally, I cloned both the opencv and opencv_contrib projects from their respective github repos, then called git checkout 3.1.0
on both. I suspect the fix I need to make is to add a rule to Makefile2
specifying to use the .so
libraries instead of .a
, though I'm inexperienced with using make
and with shared objects. Any suggestions for what to modify would be appreciated. For completeness, below is the configuration done by cmake
. Note that at one point the configuration says libavcodec
, libavfilter
, libavformat
, etc. modules are not found. I don't know if this is related to the error or how to fix it.
Detected version of GNU GCC: 49 (409) Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found suitable version "1.2.8", minimum required is "1.2.3") Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.2.8") Found OpenEXR: /usr/lib/x86_64-linux-gnu/libIlmImf.so CMake Warning at cmake/OpenCVFindLibsGUI.cmake:18 (find_package): By not providing "FindQt5Core.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Qt5Core", but CMake did not find one.Could not find a package configuration file provided by "Qt5Core" with any of the following names:
Qt5CoreConfig.cmake qt5core-config.cmake
Add the installation prefix of "Qt5Core" to CMAKE_PREFIX_PATH or set "Qt5Core_DIR" to a directory containing one of the above files. If "Qt5Core" provides a separate development package or SDK, be sure it has been installed. Call Stack (most recent call first):
CMakeLists.txt:535 (include)CMake Warning at cmake/OpenCVFindLibsGUI.cmake:19 (find_package): By not providing "FindQt5Gui.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Qt5Gui", but CMake did not find one.Could not find a package configuration file provided by "Qt5Gui" with any of the following names:
Qt5GuiConfig.cmake qt5gui-config.cmake
Add the installation prefix of "Qt5Gui" to CMAKE_PREFIX_PATH or set
"Qt5Gui_DIR" to a directory containing one of the above files. If "Qt5Gui"
provides a separate development package or SDK, be sure it has been
installed. Call Stack (most recent call first): CMakeLists.txt:535 (include)CMake Warning at cmake/OpenCVFindLibsGUI.cmake:20 (find_package): By not providing "FindQt5Widgets.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by
"Qt5Widgets", but CMake did not find one.Could not find a package configuration file provided by "Qt5Widgets" with any of the following names:
Qt5WidgetsConfig.cmake qt5widgets-config.cmake
Add the installation prefix of "Qt5Widgets" to CMAKE_PREFIX_PATH or set "Qt5Widgets_DIR" to a directory containing one of the above files. If "Qt5Widgets" provides a separate development package or SDK, be sure it has been installed. Call Stack (most recent call first):
CMakeLists.txt:535 (include)CMake Warning at cmake/OpenCVFindLibsGUI.cmake:21 (find_package): By not providing "FindQt5Test.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Qt5Test", but CMake did not find one.Could not find a package configuration file provided by "Qt5Test" with any of the following names:
Qt5TestConfig.cmake qt5test-config.cmake
Add the installation prefix of "Qt5Test" to CMAKE_PREFIX_PATH or set "Qt5Test_DIR" to a directory containing one of the above files. If "Qt5Test" provides a separate development package or SDK, be sure it has been installed. Call Stack (most recent call first):
CMakeLists.txt:535 (include)CMake Warning at cmake/OpenCVFindLibsGUI.cmake:22 (find_package): By not providing "FindQt5Concurrent.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by
"Qt5Concurrent", but CMake did not find one.Could not find a package configuration file provided by "Qt5Concurrent" with any of the following names:
Qt5ConcurrentConfig.cmake qt5concurrent-config.cmake
Add the installation prefix of "Qt5Concurrent" to CMAKE_PREFIX_PATH or set "Qt5Concurrent_DIR" to a directory containing one of the above files. If "Qt5Concurrent" provides a separate development package or SDK, be sure it has been installed. Call Stack (most recent call first):
CMakeLists.txt:535 (include)checking for module 'gstreamer-base-1.0' package 'gstreamer-base-1.0' not found checking for module 'gstreamer-video-1.0' package 'gstreamer-video-1.0' not found checking for module 'gstreamer-app-1.0' package 'gstreamer-app-1.0' not found checking for module 'gstreamer-riff-1.0'
package 'gstreamer-riff-1.0' not found checking for module 'gstreamer-pbutils-1.0' package 'gstreamer-pbutils-1.0' not found checking for module 'gstreamer-base-0.10' package 'gstreamer-base-0.10' not found checking for module 'gstreamer-video-0.10' package 'gstreamer-video-0.10' not found checking for module 'gstreamer-app-0.10' package 'gstreamer-app-0.10' not found checking for module 'gstreamer-riff-0.10' package 'gstreamer-riff-0.10' not found checking for module 'gstreamer-pbutils-0.10' package 'gstreamer-pbutils-0.10' not found checking for module 'libdc1394-2'
package 'libdc1394-2' not found checking for module 'libdc1394'
package 'libdc1394' not found checking for module 'libv4l1' package 'libv4l1' not found checking for module 'libv4l2' package 'libv4l2' not found Looking for linux/videodev.h Looking for linux/videodev.h - not found Looking for linux/videodev2.h Looking for linux/videodev2.h - found Looking for sys/videoio.h Looking for sys/videoio.h - not found checking for module 'libavcodec' package 'libavcodec' not found checking for module 'libavformat' package 'libavformat' not found checking for module 'libavutil' package 'libavutil' not found checking for module 'libswscale' package 'libswscale' not found checking for module 'libavresample' package 'libavresample' not found Looking for libavformat/avformat.h Looking for libavformat/avformat.h - found Looking for ffmpeg/avformat.h Looking for ffmpeg/avformat.h - not found checking for module 'libgphoto2' package 'libgphoto2' not found found IPP (ICV version): 9.0.1 [9.0.1] at: /home/grant/github/opencv/3rdparty/ippicv/unpack/ippicv_lnx Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE) To enable PlantUML support, set PLANTUML_JAR environment variable or pass -DPLANTUML_JAR=<filepath> option to cmake Found PythonInterp: /usr/bin/python2.7 (found suitable version "2.7.9", minimum required is "2.7") Found PythonLibs: /usr/lib/x86_64-linux-gnu/libpython2.7.so (found suitable exact version "2.7.9") Found PythonInterp: /usr/local/bin/python3.5 (found suitable version "3.5", minimum required is "3.4") Found PythonLibs: /usr/lib/x86_64-linux-gnu/libpython3.4m.so (found suitable exact version "3.5.0") VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file Caffe: NO Protobuf: NO Glog: NO HDF5: YES Module opencv_sfm disabled because the following dependencies are not found: Glog/Gflags Tesseract: NO HDF5:
YES Could NOT find PROTOBUF (missing: PROTOBUF_LIBRARY PROTOBUF_INCLUDE_DIR) Build libprotobuf from sources: libprotobuf not found into system The protocol buffer compiler not found Tesseract: NOGeneral configuration for OpenCV 3.1.0 ===================================== Version control: 3.1.0
Platform: Host: Linux 3.19.0-25-generic x86_64 CMake: 3.0.2 CMake generator: Unix Makefiles CMake build tool: /usr/bin/make Configuration: RELEASE
C/C++: Built as dynamic libs?: YES C++ Compiler: /usr/bin/c++ (ver 4.9.2) C++ flags (Release): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -mno-avx -msse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -ffunction-sections -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG C++ flags (Debug): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -mno-avx -msse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -ffunction-sections -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG C Compiler: /usr/bin/cc C flags (Release): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -mno-avx -msse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -ffunction-sections -fvisibility=hidden -O3 -DNDEBUG -DNDEBUG C flags (Debug): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -mno-avx -msse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -ffunction-sections -fvisibility=hidden -g -O0 -DDEBUG -D_DEBUG Linker flags (Release):
Linker flags (Debug):
Precompiled headers: YES Extra dependencies: /usr/lib/x86_64-linux-gnu/libQtGui.so /usr/lib/x86_64-linux-gnu/libQtTest.so /usr/lib/x86_64-linux-gnu/libQtCore.so /usr/lib/x86_64-linux-gnu/libpng.so /usr/lib/x86_64-linux-gnu/libtiff.so /usr/lib/x86_64-linux-gnu/libjasper.so /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib/x86_64-linux-gnu/libImath.so /usr/lib/x86_64-linux-gnu/libIlmImf.so /usr/lib/x86_64-linux-gnu/libIex.so /usr/lib/x86_64-linux-gnu/libHalf.so /usr/lib/x86_64-linux-gnu/libIlmThread.so /home/grant/github/ffmpeg//libavcodec.a /home/grant/github/ffmpeg//libavformat.a /home/grant/github/ffmpeg//libavutil.a /home/grant/github/ffmpeg//libswscale.a /home/grant/github/ffmpeg//libavresample.a /usr/lib/x86_64-linux-gnu/hdf5/serial/lib/libhdf5.so /usr/lib/x86_64-linux-gnu/libpthread.so /usr/lib/x86_64-linux-gnu/libz.so /usr/lib/x86_64-linux-gnu/libdl.so /usr/lib/x86_64-linux-gnu/libm.so dl m pthread rt 3rdparty dependencies: libwebp libprotobufOpenCV modules: To be built: core flann hdf imgproc ml photo reg surface_matching video dnn fuzzy imgcodecs shape videoio highgui objdetect plot superres ts xobjdetect xphoto bgsegm bioinspired dpm face features2d line_descriptor saliency text calib3d ccalib datasets rgbd stereo structured_light tracking videostab xfeatures2d ximgproc aruco optflow stitching python2 python3 Disabled: world contrib_world Disabled by dependency: - Unavailable: cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev java viz cvv matlab sfm
GUI: QT 4.x: YES (ver 4.8.6 EDITION = OpenSource) QT OpenGL support: NO OpenGL support: NO VTK support: NO
Media I/O: ZLib: /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.8) JPEG: /usr/lib/x86_64-linux-gnu/libjpeg.so (ver ) WEBP: build (ver 0.3.1) PNG: /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.2.51) TIFF: /usr/lib/x86_64-linux-gnu/libtiff.so (ver 42 - 4.0.3) JPEG 2000: /usr/lib/x86_64-linux-gnu/libjasper.so (ver 1.900.1) OpenEXR: /usr/lib/x86_64-linux-gnu/libImath.so /usr/lib/x86_64-linux-gnu/libIlmImf.so /usr/lib/x86_64-linux-gnu/libIex.so /usr/lib/x86_64-linux-gnu/libHalf.so /usr/lib/x86_64-linux-gnu/libIlmThread.so (ver Unknown) GDAL: NO
Video I/O: DC1394 1.x: NO DC1394 2.x: NO FFMPEG: YES codec: YES (ver Unknown) format: YES (ver Unknown) util: YES (ver Unknown) swscale: YES (ver Unknown) resample: YES (ver Unknown) gentoo-style: YES GStreamer: NO OpenNI: NO OpenNI PrimeSensor Modules: NO OpenNI2: NO PvAPI: NO GigEVisionSDK: NO UniCap: NO UniCap ucil: NO V4L/V4L2: NO/YES XIMEA: NO Xine: NO gPhoto2: NO
Parallel framework:
pthreadsOther third-party libraries: Use IPP: 9.0.1 [9.0.1] at: /home/grant/github/opencv/3rdparty/ippicv/unpack/ippicv_lnx Use IPP Async: NO Use VA: NO Use Intel VA-API/OpenCL: NO Use Eigen: YES (ver 3.2.2) Use Cuda: NO Use OpenCL: YES Use custom HAL: NO
OpenCL: Version: dynamic Include path: /home/grant/github/opencv/3rdparty/include/opencl/1.2 Use AMDFFT: NO Use AMDBLAS: NO
Python 2: Interpreter: /usr/bin/python2.7 (ver 2.7.9) Libraries: /usr/lib/x86_64-linux-gnu/libpython2.7.so (ver 2.7.9) numpy: /usr/local/lib/python2.7/dist-packages/numpy/core/include (ver 1.11.0) packages path: lib/python2.7/dist-packages
Python 3: Interpreter: /usr/local/bin/python3.5 (ver 3.5) Libraries: /usr/lib/x86_64-linux-gnu/libpython3.4m.so (ver 3.5.0) numpy: /usr/local/lib/python3.5/site-packages/numpy/core/include (ver 1.11.0) packages path: /usr/local/lib/python3.5/site-packages
Python (for build):
/usr/bin/python2.7Java: ant: NO JNI: /usr/lib/jvm/default-java/include /usr/lib/jvm/default-java/include /usr/lib/jvm/default-java/include Java wrappers: NO Java tests: NO
Matlab: NO
Documentation: Doxygen: NO PlantUML: NO
Tests and samples: Tests: YES Performance tests: YES C/C++ Examples: YES
Install path:
/usr/localcvconfig.h is in:
/home/grant/github/opencv/build
Configuring done Generating done