2013-10-02 121 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'时出现相同的链接器错误 –