Search code examples
gccffmpeg

How to use libraries ".lib" and ".a" files in GCC


I have simple C code that uses some functions of libavcodec in FFmpeg. I try to compile the code with GCC (on Windows using MinGW) as follows:

gcc -o mycode mycode.c

But I get a lot of errors like "undefined reference to av_free". I know that these functions are defined in the libraries of FFmpeg. I do access files like avcodec.lib and libavcodec.dll.a, but I don't know how to use them with GCC so that I can compile and make my file. How can I solve this problem?


Solution

  • Try something like:

    gcc -o mycode mycode.c -L C:\path\to\avcodec -lavcodec
    

    I don't have Windows, so I cannot test it myself.

    The point is that you need to tell gcc that some functions are in avcodec.lib / .dll. After the -L you tell where the .a / .dll is, then you must tell the linker to actually consider the avcodec.lib / .dll, that corresponds to -lavcodec.