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


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM