OpenCV2.4.9 version compilation
1) linux to view the opencv installation path and version number
View the opencv installation library under linux:
Pkg-config opencv-libs
View the installation version of opencv under linux:
Pkg-config opencv-modversion
View the opencv installation path under linux:
Find /-iname "* opencv*"
2) compile instruction
Create a library directory: mkdir install
Create a build directory: mkdir build
Enter the directory: cd build
Execute the generate Makefile:
Cmake-D WITH_CUDA=OFF\
-D CMAKE_BUILD_TYPE=Release\
-D CMAKE_INSTALL_PREFIX=cmake-D WITH_CUDA=OFF\
-D CMAKE_BUILD_TYPE=Release\
-D CMAKE_INSTALL_PREFIX=/home/packages/opencv/install\
-D WITH_IPP=OFF\
-D WITH_FFMPEG=ON\
-D BUILD_TESTS=OFF\
-D BUILD_PERF_TESTS=OFF\
-D INSTALL_PYTHON_EXAMPLES=OFF\
-D INSTALL_C_EXAMPLES=OFF\
-D PYTHON_EXECUTABLE=$ (which python)\
-D BUILD_EXAMPLES=OFF.. \
-D WITH_IPP=OFF\
-D WITH_FFMPEG=ON\
-D BUILD_TESTS=OFF\
-D BUILD_PERF_TESTS=OFF\
-D INSTALL_PYTHON_EXAMPLES=OFF\
-D INSTALL_C_EXAMPLES=OFF\
-D PYTHON_EXECUTABLE=$ (which python)\
-D BUILD_EXAMPLES=OFF..
Generate installation: make & & make install
Compilation exception
1) [98%] Linking CXX executable.. / bin/opencv_performance
.. /.. / lib/libopencv_highgui.so.2.4.9: undefined reference to `avcodec_alloc_frame'
.. /.. / lib/libopencv_highgui.so.2.4.9: undefined reference to `avcodec_encode_video'
Collect2: error: ld returned 1 exit status
Apps/haartraining/CMakeFiles/opencv_performance.dir/build.make:105: recipe for target 'bin/opencv_performance' failed
Make [2]: * * [bin/opencv_performance] Error 1
CMakeFiles/Makefile2:3388: recipe for target 'apps/haartraining/CMakeFiles/opencv_performance.dir/all' failed
Make [1]: * * [apps/haartraining/CMakeFiles/opencv_performance.dir/all] Error 2
Makefile:149: recipe for target 'all' failed
Make: * * [all] Error 2
Problem: undefined reference to `avcodec_alloc_frame'
Return null via grep-r "avcodec_alloc_frame" / query global text
The latest version of FFmpeg the implementation name of this function has been changed, download the ffmpeg-2.3.tar.bz2 source code to compile
2) ffmpeg-2.3.tar.bz2 has been compiled, but the generated libswresample.so.0 cannot be found. Copy the libswresample.so.0 to the / lib64 directory.
Usr/bin/ld: warning: libswresample.so.0, needed by / / home/dong/ffmpeg/ffmpeg-2.3/build/lib/libavcodec.so.55, not found (try using-rpath or-rpath-link)
/ / home/dong/ffmpeg/ffmpeg-2.3/build/lib/libavcodec.so.55: undefined reference to `swr_init@LIBSWRESAMPLE_0'
/ / home/dong/ffmpeg/ffmpeg-2.3/build/lib/libavcodec.so.55: undefined reference to `swr_close@LIBSWRESAMPLE_0'
/ / home/dong/ffmpeg/ffmpeg-2.3/build/lib/libavcodec.so.55: undefined reference to `swr_is_initialized@LIBSWRESAMPLE_0'
/ / home/dong/ffmpeg/ffmpeg-2.3/build/lib/libavcodec.so.55: undefined reference to `swr_free@LIBSWRESAMPLE_0'
/ / home/dong/ffmpeg/ffmpeg-2.3/build/lib/libavcodec.so.55: undefined reference to `swr_alloc@LIBSWRESAMPLE_0'
/ / home/dong/ffmpeg/ffmpeg-2.3/build/lib/libavcodec.so.55: undefined reference to `swr_convert@LIBSWRESAMPLE_0'
Collect2: error: ld returned 1 exit status
Apps/haartraining/CMakeFiles/opencv_performance.dir/build.make:105: recipe for target 'bin/opencv_performance' failed
Make [2]: * * [bin/opencv_performance] Error 1
CMakeFiles/Makefile2:3388: recipe for target 'apps/haartraining/CMakeFiles/opencv_performance.dir/all' failed
Make [1]: * * [apps/haartraining/CMakeFiles/opencv_performance.dir/all] Error 2
Makefile:149: recipe for target 'all' failed
Make: * * [all] Error
3) export PKG_CONFIG_PATH=/home/dong/opencv-2.4.9/install/lib/pkgconfig/;$PKG_CONFIG_PATH
Specifies that OpenCV first finds the compiled FFmpeg rather than the system's FFmpeg library