ffmpeg編譯問題

利用ffmpeg實現一個播放器,ffmpeg提供動態庫,但是編譯鏈接的時候遇到下面的問題:

../ffmpegWidgetPlayer/videoplayerwidget.cpp:23: error: undefined reference to 'sws_freeContext(SwsContext*)'
../ffmpegWidgetPlayer/videoplayerwidget.cpp:28: error: undefined reference to 'av_frame_free(AVFrame**)'
../ffmpegWidgetPlayer/videoplayerwidget.cpp:33: error: undefined reference to 'av_frame_free(AVFrame**)'
../ffmpegWidgetPlayer/videoplayerwidget.cpp:38: error: undefined reference to 'avcodec_close(AVCodecContext*)'
../ffmpegWidgetPlayer/videoplayerwidget.cpp:39: error: undefined reference to 'avcodec_free_context(AVCodecContext**)'
../ffmpegWidgetPlayer/videoplayerwidget.cpp:44: error: undefined reference to 'avformat_close_input(AVFormatContext**)'
../ffmpegWidgetPlayer/videoplayerwidget.cpp:55: error: undefined reference to 'avformat_network_init()'
../ffmpegWidgetPlayer/videoplayerwidget.cpp:58: error: undefined reference to 'avformat_open_input(AVFormatContext**, char const*, AVInputFormat const*, AVDictionary**)'
../ffmpegWidgetPlayer/videoplayerwidget.cpp:64: error: undefined reference to 'avformat_find_stream_info(AVFormatContext*, AVDictionary**)'
../ffmpegWidgetPlayer/videoplayerwidget.cpp:84: error: undefined reference to 'avcodec_find_decoder(AVCodecID)'
../ffmpegWidgetPlayer/videoplayerwidget.cpp:91: error: undefined reference to 'avcodec_alloc_context3(AVCodec const*)'
../ffmpegWidgetPlayer/videoplayerwidget.cpp:98: error: undefined reference to 'avcodec_parameters_to_context(AVCodecContext*, AVCodecParameters const*)'
../ffmpegWidgetPlayer/videoplayerwidget.cpp:104: error: undefined reference to 'avcodec_open2(AVCodecContext*, AVCodec const*, AVDictionary**)'
../ffmpegWidgetPlayer/videoplayerwidget.cpp:110: error: undefined reference to 'av_frame_alloc()'
../ffmpegWidgetPlayer/videoplayerwidget.cpp:117: error: undefined reference to 'av_frame_alloc()'
../ffmpegWidgetPlayer/videoplayerwidget.cpp:124: error: undefined reference to 'av_image_get_buffer_size(AVPixelFormat, int, int, int)'
../ffmpegWidgetPlayer/videoplayerwidget.cpp:125: error: undefined reference to 'av_malloc(unsigned long)'
../ffmpegWidgetPlayer/videoplayerwidget.cpp:128: error: undefined reference to 'av_image_fill_arrays(unsigned char**, int*, unsigned char const*, AVPixelFormat, int, int, int)'
../ffmpegWidgetPlayer/videoplayerwidget.cpp:131: error: undefined reference to 'sws_getContext(int, int, AVPixelFormat, int, int, AVPixelFormat, int, SwsFilter*, SwsFilter*, double const*)'
../ffmpegWidgetPlayer/videoplayerwidget.cpp:148: error: undefined reference to 'av_read_frame(AVFormatContext*, AVPacket*)'
../ffmpegWidgetPlayer/videoplayerwidget.cpp:151: error: undefined reference to 'avcodec_send_packet(AVCodecContext*, AVPacket const*)'
../ffmpegWidgetPlayer/videoplayerwidget.cpp:157: error: undefined reference to 'avcodec_receive_frame(AVCodecContext*, AVFrame*)'
../ffmpegWidgetPlayer/videoplayerwidget.cpp:164: error: undefined reference to 'sws_scale(SwsContext*, unsigned char const* const*, int const*, int, int, unsigned char* const*, int const*)'
../ffmpegWidgetPlayer/videoplayerwidget.cpp:170: error: undefined reference to 'av_frame_unref(AVFrame*)'
../ffmpegWidgetPlayer/videoplayerwidget.cpp:174: error: undefined reference to 'av_packet_unref(AVPacket*)'
../ffmpegWidgetPlayer/videoplayerwidget.cpp:187: error: undefined reference to 'sws_freeContext(SwsContext*)'
../ffmpegWidgetPlayer/videoplayerwidget.cpp:188: error: undefined reference to 'sws_getContext(int, int, AVPixelFormat, int, int, AVPixelFormat, int, SwsFilter*, SwsFilter*, double const*)'
collect2: error: ld returned 1 exit status
make: *** [Makefile:288: ffmpegWidgetPlayer] Error 1
10:29:50: 進程"/usr/bin/make"退出,退出代碼 2 。
Error while building/deploying project ffmpegWidgetPlayer (kit: Desktop Qt 5.15.2 GCC 64bit)
When executing step "Make"
10:29:50: Elapsed time: 00:03.

?通過分析報錯信息可以看到在鏈接階段提示ffmpeg相關的api找不到符號,看到這個問題百思不得其解,該工程我是利用qt編譯鏈接,可以肯定的是pro文件中已經通過LIBS關鍵字指明了依賴庫的路徑和依賴庫的名稱,但是仍然提示找不到,最后通過查閱資料,才了解問題產生的原因:qt工程是c++代碼,ffmpeg是c原因編寫的,當c++代碼調用C庫時對c++代碼中調用的頭文件需要使用extern "C"包含起來,以此讓編譯器按照C的方式編譯ffmpeg相關的頭文件

解決方法如下:

#include <QWidget>
#include <QImage>
#include <QTimer>
#include <QPainter>
#include <QCoreApplication>
#include <QResizeEvent>
extern "C"   //按照C語言方式編譯api接口
{
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
#include <libswscale/swscale.h>
#include <libavutil/avutil.h>
#include <libpostproc/postprocess.h>
#include <libavutil/ffversion.h>
#include <libavutil/imgutils.h>
}

總結

下面對編譯階段“undefined reference to”的報錯原因進行總結,希望能夠大家有所幫助:

  • 產生這個報錯簡單的是就是依賴庫未包含,就是說未指定依賴庫的路徑和和依賴庫名稱,這個通過LIBS關鍵字就可以解決
  • 如果確定LIBS等類似的方式已經指明依賴庫的路徑和依賴庫名稱,還是有這個報錯,那么確認下是否是C++代碼調用了C語言的庫,如果屬實,那么就是用extern "C"關鍵字包含C庫的頭文件

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/209585.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/209585.shtml
英文地址,請注明出處:http://en.pswp.cn/news/209585.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

JWT介紹及演示

JWT 介紹 cookie(放在瀏覽器) cookie 是一個非常具體的東西&#xff0c;指的就是瀏覽器里面能永久存儲的一種數據&#xff0c;僅僅是瀏覽器實現的一種數據存儲功能。 cookie由服務器生成&#xff0c;發送給瀏覽器&#xff0c;瀏覽器把cookie以kv形式保存到某個目錄下的文本…

JavaScript 金額元轉化為萬

function dealNum(price){if (price 0) {return 0元}const BASE 10000const decimal 0const SIZES ["", "萬", "億", "萬億"];let i undefined;let str "";if (price) {if ((price > 0 && price < BASE…

p標簽的水平居中和垂直居中

1行內塊元素水平居中垂直居中 行內元素和行內塊元素水平居中&#xff0c;給其父元素添加text-align:center&#xff1b;所以案例里面給one加了 text-align: center之后span就會水平居中了。在設置span行高和高都是一樣的 20px;這樣就實現上下居中了。 2塊級元素P元素水平居中…

通過命令行輸入參數控制激勵

1)在命令行的仿真參數&#xff08;SIM_OPT&#xff09;加上&#xff1a;“var_a100 var_b99” 2)在環境中調用&#xff1a; $test$plusargs("var_a")&#xff1b;如果命令行存在這個字符&#xff0c;返回1&#xff0c;否則返回0&#xff1b; $value$plusargs(&qu…

vue2 el-input里實現打字機 效果

vue2 el-input里實現打字機 效果 <el-col :span"24" v-if"ifshowOtherDesc""><el-form-item label"分析" prop"otherDesc"><el-input type"textarea" :disabled"disabled" autofocus"t…

藍牙物聯網對接技術難點有哪些?

#物聯網# 藍牙物聯網對接技術難點主要包括以下幾個方面&#xff1a; 1、設備兼容性&#xff1a;藍牙技術有多種版本和規格&#xff0c;如藍牙4.0、藍牙5.0等&#xff0c;不同版本之間的兼容性可能存在問題。同時&#xff0c;不同廠商生產的藍牙設備也可能存在兼容性問題。 2、…

0-1背包問題

二維版: import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader;public class Main {static int N 1010;static int[][] dp new int[N][N]; //dp[i][j] 只選前i件物品,體積 < j的最優解static int[] w new int[N]; //存儲價…

Day03 嵌入式---中斷

目錄 一、簡單介紹 二、總體框架 三、NVIC 3.2 NVIC的寄存器 3.3 中斷向量表 3.4 中斷優先級 3.5 NVIC優先級分組 3.6 NVIC配置 3.6.1、設置中斷分組 3.6.2、初始化 四、EXTI 外部中斷 4.1.EXTI的基本概念 4.2.EXTI的?作原理 4.3 EXTI配置 五、SYSCFG 5.1 SYS…

字符串函數`strlen`、`strcpy`、`strcmp`、`strstr`、`strcat`的使用以及模擬實現

文章目錄 &#x1f680;前言&#x1f680;庫函數strlen??strlen的模擬實現 &#x1f680;庫函數strcpy??strcpy的模擬實現 &#x1f680;strcmp??strcmp的模擬實現 &#x1f680;strstr??strstr的模擬實現 &#x1f680;strcat??strcat的模擬實現 &#x1f680;前言 …

ReactJS和VueJS的簡介以及它們之間的區別

本文主要介紹ReactJS和VueJS的簡介以及它們之間的區別。 目錄 ReactJS簡介ReactJS的優缺點ReactJS的應用場景VueJS簡介VueJS的優缺點VueJS的應用場景ReactJS和VueJS的區別 ReactJS簡介 ReactJS是一個由Facebook開發的基于JavaScript的前端框架。它是一個用于構建用戶界面的庫&…

【C語言】——函數遞歸,用遞歸簡化并實現復雜問題

文章目錄 前言一、什么是遞歸二、遞歸的限制條件三、遞歸舉例1.求n的階乘2. 舉例2&#xff1a;順序打印一個整數的每一位 四、遞歸的優劣總結 前言 不多廢話了&#xff0c;直接開始。 一、什么是遞歸 遞歸是學習C語言函數繞不開的?個話題&#xff0c;那什么是遞歸呢&#xf…

電商平臺商品銷量API接口,30天銷量API接口接口超詳細接入方案說明

電商平臺商品銷量API接口的作用主要是幫助開發者獲取電商平臺上的商品銷量信息。通過這個接口&#xff0c;開發者可以在自己的應用或網站中實時獲取商品的銷量數據&#xff0c;以便進行銷售分析、庫存管理、市場預測等操作。 具體來說&#xff0c;電商平臺商品銷量API接口的使…

RocketMq集成SpringBoot(待完善)

環境 jdk1.8, springboot2.7.3 Maven依賴 <parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.7.3</version><relativePath/> <!-- lookup parent from…

vue3 筆記 - 聲明式 一

官網&#xff1a;Vue.js - 漸進式 JavaScript 框架 | Vue.js vue3編寫有聲明式和響應式。該文章僅記錄聲明式。vue3聲明式與vue2相同。 一、生命周期 創建之前 beforeCreate()已創建 created()掛載之前 beforeMount()已掛載 mounted()銷毀之前 beforeUnmount()已銷毀 unmoun…

java面試-Dubbo和zookeeper運行原理

遠離八股文&#xff0c;面試大白話&#xff0c;通俗且易懂 看完后試著用自己的話復述出來。有問題請指出&#xff0c;有需要幫助理解的或者遇到的真實面試題不知道怎么總結的也請評論中寫出來&#xff0c;大家一起解決。 java面試題匯總-目錄-持續更新中 分布式注冊中心和服務調…

Unity中后處理簡介

文章目錄 前言一、后處理的原理二、我們看一下Unity文檔中&#xff0c;內置的后處理前后的效果后處理前&#xff1a;后處理后&#xff1a; 前言 我們在這篇文章中&#xff0c;了解一下Unity中的后處理效果 后期處理概述 一、后處理的原理 在后處理的過程中&#xff0c;我們主…

Java當中常用的算法

文章目錄 算法二叉樹左右變換數據二分法實現 冒泡排序算法插入排序算法快速排序算法希爾排序算法歸并排序算法桶排序算法基數排序算法分治算法漢諾塔問題動態規劃算法引子代碼實現背包問題 KMP算法什么是KMP算法暴力匹配KMP算法實現 今天我們來看看常用的算法&#xff0c;開干。…

《微信小程序開發從入門到實戰》學習四十五

4.4 云函數 云函數是開發者提前定義好的、保存在云端并且將在云端運行的JS函數。 開發者先定義好云函數&#xff0c;再使用微信開發工具將云函數上傳到云空間&#xff0c;在云開發控制臺中可看到已經上傳的云函數。 云函數運行在云端Node.js環境中。 小程序端通過wx.cloud.…

IP地址定位技術為網絡安全建設提供全新方案

隨著互聯網的普及和數字化進程的加速&#xff0c;網絡安全問題日益引人關注。網絡攻擊、數據泄露、欺詐行為等安全威脅層出不窮&#xff0c;對個人隱私、企業機密和社會穩定構成嚴重威脅。在這樣的背景下&#xff0c;IP地址定位技術應運而生&#xff0c;為網絡安全建設提供了一…

Python Selenium 自動登入1688

Python Selenium是一個用于自動化Web瀏覽器操作的庫。它提供了一組功能強大的工具和API&#xff0c;可以模擬用戶在瀏覽器中的行為&#xff0c;并執行各種任務&#xff0c;如點擊、輸入文本、提交表單等。 要使用Python Selenium登錄1688網站&#xff0c;需要進行以下步驟&…