OpenCv 3.1.0 - 编译失败

时间:2016-11-02 23:29:09

标签: linux debian opencv3.0

我正在尝试在debian 8上安装OpenCv 3.1.0(它提供了python3绑定)

遵循官方网站http://docs.opencv.org/3.1.0/d7/d9f/tutorial_linux_install.html上的标准程序,该过程失败

[ 30%] Building CXX object modules/photo/CMakeFiles/opencv_photo.dir/opencl_kernels_photo.cpp.o
Linking CXX shared library ../../lib/libopencv_shape.so
[ 30%] Built target opencv_shape
Linking CXX shared library ../../lib/libopencv_photo.so
[ 30%] Built target opencv_photo
Makefile:147: recipe for target 'all' failed
make: *** [all] Error 2
[  0%] Built target opencv_core_pch_dephelp
[  0%] Built target pch_Generate_opencv_core
[  4%] Built target opencv_core
[  4%] Built target opencv_ts_pch_dephelp
[  4%] Built target pch_Generate_opencv_ts
[  4%] Built target opencv_imgproc_pch_dephelp
[  4%] Built target pch_Generate_opencv_imgproc
[  9%] Built target opencv_imgproc
[  9%] Built target opencv_imgcodecs_pch_dephelp
[  9%] Built target pch_Generate_opencv_imgcodecs
[ 11%] Built target opencv_imgcodecs
[ 11%] Built target opencv_videoio_pch_dephelp
[ 11%] Built target pch_Generate_opencv_videoio
Linking CXX shared library ../../lib/libopencv_videoio.so
/usr/bin/ld: /usr/local/lib/libavcodec.a(avpacket.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libavcodec.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
modules/videoio/CMakeFiles/opencv_videoio.dir/build.make:280: recipe for target 'lib/libopencv_videoio.so.3.1.0' failed
make[2]: *** [lib/libopencv_videoio.so.3.1.0] Error 1
CMakeFiles/Makefile2:4076: 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

有关此问题的更多信息,请访问http://wiki.open-si.org/trac-notes/ticket/10

1 个答案:

答案 0 :(得分:1)

这个错误来自ffpmeg使用的一些库不用--enable-shared编译很可能是libvpx,请使用" make clean"首先使用--enable-shared重置./configure并重新编译这些库。

make clean
./configure --enable-shared --disable-static
make
sudo make install

另一个选择,假设你没有在OpenCV中使用FFMPEG:你可以禁止它被编译:

当你运行Cmake时,即:

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D PYTHON2_PACKAGES_PATH=~/.virtualenvs/cv/lib/python2.7/site-packages \
    -D PYTHON2_LIBRARY=/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/bin \
    -D PYTHON2_INCLUDE_DIR=/usr/local/Frameworks/Python.framework/Headers \
    -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON \
    -D BUILD_EXAMPLES=ON \
    -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules ..

添加标志-DWITH_FFMPEG=0以不编译FFMPEG部分