編譯FFmpeg問題彙總

1.error: undefined reference to ‘av_version_info()’

出錯原因: ffmpeg是純C的庫,頭文件沒有做好C++調用的準備

解決方案:用extern “C”{}套住ffmpeg頭文件,用C語言的編譯規則來編譯ffmpeg代碼,就可以了

extern "C"{
    #include <libavutil/avutil.h>
}

2.libavutil/log.c:186: error: undefined reference to ‘stderr’

出錯原因:

代碼中使用了大量的標準IO設備:stderr 等,這些在NDK15以後,這些都不被支持了,代碼本身沒問題,只是編譯器鏈接時找不到對應的靜態庫定義了;

解決方案:

在編譯選項中添加語句-DANDROID_API=[你的android API版本號]即可; 比如我的測試手機爲android 5.1.1 對應 API = 22,編譯選項中應該添加:-DANDROID_API=22

adb shell 獲取 android 系統版本: adb shell getprop ro.build.version.release

adb shell 獲取 android 系統 API 版本: adb shell getprop ro.build.version.sdk

3.libavformat/utils.c:513: error: undefined reference to ‘av_parser_close’

出錯原因: 鏈接靜態庫先後順序不正確,引起的符號定義找不到。

解決方案:2種

  1. 修改靜態庫的鏈接順序。

    target_link_libraries(
    				native-lib
            # 先把有依賴的庫,先依賴進來
            avformat avcodec avfilter avutil swresample swscale
            log)
    
  2. 忽略靜態庫的鏈接順序。

    target_link_libraries(
    native-lib
    -Wl,--start-group
    avcodec avfilter avformat avutil swresample swscale
    -Wl,--end-group
    log)
    

4.libavformat/http.c:1649: error: undefined reference to ‘inflateEnd’

出錯原因: 找不到的z庫中的函數的實現。因爲 ffmpeg 依賴了z庫。編譯ffmpeg的時候如果仔細看編譯時輸出的日誌,就可以看到 External libraries: zlib

解決方案:添加z庫的依賴。

target_link_libraries(
        native-lib
        -Wl,--start-group
        avcodec avfilter avformat avutil swresample swscale
        -Wl,--end-group
        log
        z
)

5.libavformat/hls.c:845: error: undefined reference to ‘atof’

出錯原因:

Google have moved some of the C standard library functions like atof() from being inline functions in header files to normal functions. The latest NDKs will default to building a .so that is only compatible with the latest Android devices that have the atof() function in the device’s standard C library (libc.so). This means if you run a library on an older device that has an older version of the C library, you will get an error loading the dll as the expected atof() function will not exist.

Google已經將一些C標準庫函數(如atof())從頭文件中的內聯函數移到了普通函數。最新的ndk將默認構建一個.so,它只與在設備的標準C庫(libc.so)中具有atof()函數的最新Android設備兼容。這意味着,如果在具有較舊版本的C庫的較舊設備上運行庫,由於預期的atof()函數不存在,因此在加載該dll時將出現錯誤。

解決方案: 修改ffmpeg編譯腳本,指定Android API版本爲17,重新編譯。

這裏又有一個問題:

libavcodec/v4l2_buffers.c:434:44: error: call to 'mmap' declared with attribute error: mmap is not available > with _FILE_OFFSET_BITS=64 when using GCC until android-21. Either raise your minSdkVersion, disable > _FILE_OFFSET_BITS=64, or switch to Clang.

所以21版本以下,需要取消 _FILE_OFFSET_BITS宏定義。添加編譯參數: -U_FILE_OFFSET_BITS

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章