Android 在引用 FFmpeg 靜態(tài)庫時(shí),出現(xiàn) libavformat/hls.c:881: error: undefined reference to ‘a(chǎn)tof’

錯(cuò)誤信息如下:

  libavformat/hls.c:881: error: undefined reference to 'atof'
  libavformat/hlsenc.c:1233: error: undefined reference to 'atof'
  libavformat/http.c:1758: error: undefined reference to 'inflateEnd'
  libavformat/http.c:773: error: undefined reference to 'inflateEnd'
  libavformat/http.c:774: error: undefined reference to 'inflateInit2_'
  libavformat/http.c:779: error: undefined reference to 'zlibCompileFlags'
  libavformat/http.c:1535: error: undefined reference to 'inflate'
  libavformat/id3v2.c:1031: error: undefined reference to 'uncompress'
  libavformat/img2dec.c:266: error: undefined reference to 'glob'
  ...

造成這種問題的原因有三個(gè):

  1. 有可能是在編譯 FFmpeg 庫時(shí) Android API 版本太高導(dǎo)致,具體出錯(cuò)原因可以參考原文解釋:

    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.

    解決方案: 將 FFmpeg 編譯腳本 Android API 版本改為 17 ,重新編譯

  2. FFmpeg 庫的依賴順序錯(cuò)誤,導(dǎo)致定義的符號找不到,造成編譯錯(cuò)誤。
    簡單說一下編譯鏈接工作原理:

  • 鏈接器從左往右掃描目標(biāo)文件和靜態(tài)庫

  • 掃描發(fā)現(xiàn)未解析的符號會先記住這個(gè)未解析的符號

  • 當(dāng)掃描到后面的靜態(tài)庫時(shí),找到了前面未解析的符號,會提取相關(guān)代碼

  • 最終沒有任何未解析的符號,編譯鏈接工作完成

    既然知道工作原理了,只需要把依賴順序?qū)憣秃茫?/p>

avfilter avformat avcodec avutil swresample swscale
  1. 因?yàn)槭且腱o態(tài)庫,F(xiàn)Fmpeg 需要依賴 zlib 庫,所以在鏈接 FFmpeg 靜態(tài)庫時(shí),需要加入 zlib 庫
target_link_libraries(...
        avfilter avformat avcodec avutil swresample swscale
                      z)
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • error: undefined reference to 'av_version_info()' 出錯(cuò)原因:ff...
    Damon_He閱讀 3,459評論 2 7
  • - 1. Webbench Webbench是一個(gè)在linux下使用的非常簡單的網(wǎng)站壓測工具。它使用fork()模...
    gc_jp閱讀 1,193評論 0 0
  • 值得學(xué)習(xí)的C語言開源項(xiàng)目 WebbenchWebbench是一個(gè)在Linux下使用的非常簡單的網(wǎng)站壓測工具。它使用...
    資深小夏閱讀 3,590評論 0 49
  • 關(guān)于 C++ 框架、庫和資源的一些匯總列表,內(nèi)容包括:標(biāo)準(zhǔn)庫、Web應(yīng)用框架、人工智能、數(shù)據(jù)庫、圖片處理、機(jī)器學(xué)習(xí)...
    RitchieS閱讀 363評論 0 0
  • 我是黑夜里大雨紛飛的人啊 1 “又到一年六月,有人笑有人哭,有人歡樂有人憂愁,有人驚喜有人失落,有的覺得收獲滿滿有...
    陌忘宇閱讀 8,831評論 28 54

友情鏈接更多精彩內(nèi)容