Linking a program with ffmpeg libraries

For the developers that use FFmpeg in their software.
Post Reply
Granjow
Posts: 2
Joined: Fri Feb 10, 2012 2:28 pm

Linking a program with ffmpeg libraries

Post by Granjow » Fri Feb 10, 2012 2:58 pm

Hello,

I'm usually developing on Linux. Now I have a program that I need to compile on Windows; it is written in Qt and uses ffmpeg libraries (libavcodec etc.) and the only reason it does not run yet are linker errors. Dozens like:
lib\libvideo.a(readVideo.c.obj):readVideo.c:(.text+0xb7): undefined reference to `avcodec_alloc_frame'
lib\libvideo.a(readVideo.c.obj):readVideo.c:(.text+0x110): undefined reference to `av_register_all'
lib\libvideo.a(readVideo.c.obj):readVideo.c:(.text+0x115): undefined reference to `avformat_network_init'
lib\libvideo.a(readVideo.c.obj):readVideo.c:(.text+0x13c): undefined reference to `avformat_open_input'
lib\libvideo.a(readVideo.c.obj):readVideo.c:(.text+0x187): undefined reference to `avformat_find_stream_info'
lib\libvideo.a(readVideo.c.obj):readVideo.c:(.text+0x1d9): undefined reference to `av_dump_format'
lib\libvideo.a(readVideo.c.obj):readVideo.c:(.text+0x303): undefined reference to `avcodec_find_decoder'
What am I doing wrong? How do I link to ffmpeg libraries correctly (statically, preferredly)?

I'm currently using Cygwin/MinGW on Windows 7, 64 bit.

thanks
Granjow

ramiro
Posts: 157
Joined: Tue May 10, 2011 12:56 am

Re: Linking a program with ffmpeg libraries

Post by ramiro » Sat Feb 11, 2012 6:21 pm

the order of static libraries matters on the command line

Granjow
Posts: 2
Joined: Fri Feb 10, 2012 2:28 pm

Re: Linking a program with ffmpeg libraries

Post by Granjow » Mon Feb 13, 2012 6:16 pm

So how would I link this program?

i586-mingw32msvc-gcc -fPIC -v -Wall dumpVideoInfo.c -Iffmpeg/ -o dumpVideoInfo.exe -L fmpeg-git-fd0b8d5-win64-dev/lib/ -lavformat -lavutil gives me errors all time, no matter which order I chose.
#include <stdio.h>
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"

int main(int argc, char *argv[])
{
char *filename;
if (argc > 1) {
filename = argv[1];
} else {
printf("No video file given.");
return 2;
}

av_register_all();

AVFormatContext *pFormatContext = NULL;

printf("Reading info for file %s.\n", filename);
fflush(stdout);

int ret;
if ((ret = avformat_open_input(&pFormatContext, filename, NULL, NULL)) != 0) {
printf("Could not open file %s.\n", filename);
return 2;
}
if (avformat_find_stream_info(pFormatContext, NULL) < 0) {
printf("No stream information found.\n");
return 2;
}
av_dump_format(pFormatContext, 0, filename, 0);

av_free(pFormatContext);
return 0;
}

Post Reply