2013-10-02 120 views
0

我試圖建立一個非常簡單的Qt程序使用FFMpeg庫。鏈接器錯誤與ffmpeg

目前我只想打開和關閉視頻文件。

這裏是我的項目文件:

QT += core gui 
TARGET = avtest01 
TEMPLATE = app 
INCLUDEPATH += /usr/local/include 
LIBS += -L/usr/local/lib -lavformat 
SOURCES += main.cpp 

而且我的代碼:

#include <QDebug> 

extern "C" { 
#include <libavformat/avformat.h> 
} 

int main(int argc, char *argv[]) 
{ 
    if(argc > 1) 
    { 
     AVFormatContext *format_context; 
     qDebug() << argv[1]; 
     if(avformat_open_input(&format_context, argv[1], NULL, NULL) == 0) 
     { 
      qDebug() << "open"; 
      avformat_close_input(&format_context); 
     } 
     else 
      qDebug() << "error opening " << argv[1]; 
    }  
    return 0; 
} 

不幸的是,連接失敗:

Undefined symbols for architecture x86_64: 
    "avformat_open_input(AVFormatContext**, char const*, AVInputFormat*, AVDictionary**)", referenced from: 
    _main in main.o 
    "avformat_close_input(AVFormatContext**)", referenced from: 
    _main in main.o 

我使用Qt 5.1.0上蘋果系統。

+0

不合理不加評論? –

+0

我在調用'avformat_open_input'時遇到同樣的問題。你做了什麼來解決這個問題?您爲MacOS創建* FFmpeg *的方式有多不同? –

回答

1

您的代碼爲我工作後,我添加av_register_all();主。

我的猜測是你有avformat編譯爲32位。您可以在終端中運行file /usr/local/lib/libavformat.dylib進行確認。

輸出應該是這樣的:

/usr/local/lib/libavformat.dylib: Mach-O 64-bit dynamically linked shared library x86_64 
+1

我不得不鏈接其他庫,但我認爲這是由於我所做的ffmpeg編譯(來自http://ffmpeg.org/trac/ffmpeg/wiki/MacOSXCompilationGuide) –

+1

添加av_register_all()觸發了所有其他鏈接錯誤。 –

+0

@MartinDelille你做了什麼不同的Wrt爲MacOS構建* FFmpeg *?我正在使用[這裏]的腳本使用靜態構建(https://github.com/kewlbear/FFmpeg-iOS-build-script)。調用'avformat_open_input'時出現相同的鏈接器錯誤 –