runtime error when linking ffmpeg libraries in qt

2019-07-22 03:18发布

问题:

I'm quite new around here but i hear that if you want a question answered, stackoverflow is the place to ask it >.<. So i hope that my question isn't too trivial that everyone will get annoyed at my lack of research (I've tried googling for two days already D= no progress!) I've also asked this question in the Qt forums, but i figured i'd ask here too.

so...

For the last few days I’ve been fiddling around with opengl and the like, trying to write a video player.

However, when i try to import the ffmpeg libraries (avcodec, avformat, avutils etc), an error occurs on runtime (the program compiles fine). When compiled and run in debug mode, the error message gives me only a memory address and error code 135 (DLL not found).

This error occurs when i include a function from those libraries in my code (e.g. av_register_all()) and it occurs regardless of whether the function is actually called.

So i’m thinking that I’m doing something wrong when linking these libraries. I’m currently using: Windows vista (32bit), Qt creator 2.4.1 based on Qt 4.7.4 (32bit), Zeranoe’s FFmpeg build git-3233ad4 (2012-06-30)

My .pro file consists of:

QT       += core gui opengl

TARGET = test
TEMPLATE = app


SOURCES += main.cpp\
        mainwindow.cpp \
    glwidget.cpp

HEADERS += mainwindow.h \
    glwidget.h \

FORMS    += mainwindow.ui


LIBS += -L"$$_PRO_FILE_PWD_/libraries/ffmpeg/libs/" -lavcodec -lavformat -lavutil
INCLUDEPATH += libraries/ffmpeg/includes

I’ve tried many variations to the LIBS += line and checked my filepath many times. However, the DLL not found error occurs in all of these variations =(.

Is there something I’m forgetting when doing these includes?

Thanks in advance >.<, (young and naive) aspiring dev

回答1:

Since the error says that a DLL is not found and it happens when you include ffmpeg functions, it means that the ffmpeg libraries are dynamically linked (i.e. they're DLLs). That means that for your exe to work, it needs to load the ffmpeg DLLs. You need to have those DLLs in the same directory as your exe file. Copy them there. Use dependency walker to see which DLLs you need to copy, but they should look something like avcodec-52.dll, avdevice-52.dll, avformat-52.dll, avutil-49.dll, and maybe a few more, depending on your build of ffmpeg.