Compile opencv3.1 + ffmpeg in CentOS 7.1
The project needs to compile opencv 3.1 with ffmpeg on the server. Previously, opencv was used only on windows, and compiling once was very painful. Therefore, this time we were fully prepared.
Compile ffmpeg
1. First download the source code and put it in the/ffmpeg directory.
2. Modify the config. Because there is no sudo permission, the default installation path should be changed. Compile opencv to call the dynamic library, so shared items should be added (very pitfall, for the first time not to increase the new version)
./Configure -- enable-shared -- prefix =./install
3. make
Then an error occurs.
- /Usr/bin/ld: libavcodec/mqc. o: relocation R_X86_64_32 against '. rodata' cannotbe used when making a shared object; recompile with-fPIC
- Libavcodec/mqc. o: erroradding symbols: Bad value
- Collect2: error: ld returned 1 exitstatus
Solution:
- Add config. mak L75 to-fPIC and re-compile
- HOSTCFLAGS =-O3-g-std = c99-Wall-fPIC (order may be different)
This time
Make install
Complete.
Compile opencv
1. Source Code
2. cd./opencv/
Mkdir build
Cd build
Cmake-D CMAKE_BUILD_TYPE = RELEASE-DCMAKE_INSTALL_PREFIX =./install ..
The configuration options are displayed. The default value of ffmpeg is yes.
3. make
Error
/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: could not read symbols: Bad value
It is said that the bug of opencv lies in the process of connecting libavcodec. a to the dynamic library. Here are three solutions (you will know how long I am stuck here ):
(1) Add the shared option when compiling ffmpeg as described above.
(2) Set CMAKE_CXX_FLAGS "$ {CMAKE_CXX_FLAGS}-fPIC", but it is not easy for me to try.
(3) Delete libavformat. a libavutil. a libavcodec. a libswscale. a from/usr/local/lib (the Library directory of ffmpeg), compile opencv, and put it back.
The final solution to my problem is (1) (3)
Then make & make install
Complete
For more information, see
Http://blog.csdn.net/jinatom/article/details/7982612