ubuntu 14.04 编译opencv-3.4.2 报错解决:
错误信息:
/usr/bin/ld: /usr/local/lib/libavformat.a(allformats.o): relocation R_X86_64_32 against `.bss' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libavformat.a: error adding symbols: 错误的值
collect2: error: ld returned 1 exit status
make[2]: *** [lib/libopencv_videoio.so.3.4.2] 错误 1
make[1]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/all] 错误 2
make[1]: *** 正在等待未完成的任务....
原因:
ffmpeg未安装或配置不对
解决办法:
1 下载ffmpeg: https://ffmpeg.org/releases/ffmpeg-4.2.1.tar.bz2
2 编译ffmpeg
2.1 安装依赖项
$ sudo apt-get install yasm
$ sudo apt-get install libx264-dev
$ sudo apt-get install libfaac-dev libmp3lame-dev libtheora-dev libvorbis-dev libxvidcore-dev libxext-dev libxfixes-dev
2.2 编译
$ cd ffmpeg-4.2.1/
$ # (后面的–enable-nonfree –enable-pic –enable-shared很重要)
$ ./configure --prefix=/usr/local/ffmpeg --enable-nonfree --enable-pic --enable-shared
$ make -j
$ make install
2.3 修改/etc/profile 或 ~/.bashrc
$ vim /etc/profile
$ export FFMPEG_HOME=/usr/local/ffmpeg
$ export PATH=$FFMPEG_HOME/bin:$PATH
2.4 重新导入环境变量
$ source /etc/profile 或 source ~/.bashrc
2.5 测试ffmpeg
$ ffmpeg --version
输出:
lpadas1@lpadas1:~$ ffmpeg
ffmpeg version 4.2.git Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.4)
configuration: --prefix=/usr/local/ffmpeg --enable-nonfree --enable-pic --enable-shared
libavutil 56. 36.101 / 56. 36.101
libavcodec 58. 65.100 / 58. 65.100
libavformat 58. 35.101 / 58. 35.101
libavdevice 58. 9.101 / 58. 9.101
libavfilter 7. 69.101 / 7. 69.101
libswscale 5. 6.100 / 5. 6.100
libswresample 3. 6.100 / 3. 6.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
[必须包含这些才算成功]
3 重新配置编译opencv
$ tar xvf opencv-3.4.2.tar.gz
$ cd opencv-3.4.2/
$ mkdir build $ cd build
$ cmake -D CMAKE_INSTALL_PREFIX=/usr/local -D CMAKE_BUILD_TYPE=Release ..
$ make -j
$ make install