0

In program.c, I would like to use a method 'avcodec_register_all()' defined in libavcodec/avcodec.h.

Running

gcc program.c -L$HOME/ffmpeg/lib/libavfilter.a -L$HOME/ffmpeg/lib/libavcodec.a 

Gives me an error

/tmp/ccNeQywU.o: In function `main': program.c:(.text+0x3f): undefined reference to `avcodec_register_all' collect2: ld returned 1 exit status 

Spelling is correct and the function is defined. Why is this happening?

program.c

#include <stdio.h> int main (int args, char *argv[]) { avcodec_register_all(); } 
9
  • 3
    Try -L$HOME/ffmpeg/lib/ -lavfilter -lavcodec Commented Mar 14, 2014 at 21:23
  • Named, That gave me about 1000 undefined reference errors. Commented Mar 14, 2014 at 21:26
  • is avcodec_register_all one of them? or is that error gone now? Commented Mar 14, 2014 at 21:27
  • avcodec_register_all undefined reference error is gone, but I have undefined reference errors for other methods. Commented Mar 14, 2014 at 21:35
  • Then look for the libraries where those functions are defined in and add them the same way. Commented Mar 14, 2014 at 21:36

3 Answers 3

4

It is like this

gcc -static -lavfilter -lavcodec -L/HOME/ffmpeg/lib/ 

You need to include the file avcodec.h and also add the path to that file in your include path flags to gcc.

gcc -static -lavfilter -lavcodec -L$HOME/ffmpeg/lib/ -I$HOME/ffmpeg/include 

The static is given because your are trying to use a *.a library and not *.so (dynamic).

Sign up to request clarification or add additional context in comments.

4 Comments

Running 'gcc -lavfilter -lavcondec -L/$HOME/ffmpeg/lib/ -I/$HOME/ffmpeg/include program.c' gives me '/usr/bin/ld: cannot find -lavcondec collect2: ld returned 1 exit status'
I had a typo as well, I used avcondec when is avcodec, sorry
Running 'gcc -static -lavfilter -lavcodec -L/$HOME/ffmpeg/lib/ -I/$HOME/ffmpeg/include program.c' gives 'undefined reference to `avcodec_register_all''
check edit again, please add the include "avcodec.h"
0

Use -lavcodec with the existing parameters to gcc

Comments

0

One of the reasons may be that the function avcodec_register_all() is defined in a C++ file. It should be defined as extern "C" in avcodec.h and the library should be compiled with this proper avcodec.h.

1 Comment

In this case, the function is defined in C.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.