> Then I can compile and link using the following command line:
> gcc  -o ffmpeg_grabber ffmpeg_grabber_03.c -Wall -ggdb $(pkg-config --cflags 
> libavformat libavcodec libswresample libswscale libavutil sdl) $(pkg-config 
> --libs libavformat libavcodec libswresample libswscale libavutil sdl) -lm 
> 
> But I have a lot of link errors (undefined a lot of things) removing 
> pkg-config:
> gcc  -o test test.c -Wall -lavformat -lavcodec -lswresample -lswscale 
> -lavutil -lm
> 
> The question is: How to avoid undefine errors without using the pkg-config?

When static linking, you need to link not only the ffmpeg libraries themselves, 
but all the libraries that they link to in turn.  In this command:
> pkg-config --libs libavformat libavcodec libswresample libswscale libavutil 
> sdl


`pkg-config --libs` gets the link flags necessary (there’s also a --cflags 
option too), including all those indirectly needed libraries, to link.  You can 
run pkg-config --libs on the command line to see the list.

This list will not always be the same.  My Mac, for example, includes pthreads 
among the automatically-linked system libraries, so there will be no 
‘-lpthreads’, but it includes -L/opt/local/lib, because it’s installed in a 
non-default place where the linker won’t look.  Link flags also depend on what 
ffmpeg was configured and built with: for example, if libfoobar is installed, 
there could be a dependency for -lfoobar; but if missing when I ran ./configure 
on ffmpeg, then I might have ffmpeg but without whatever capabilities foobar 
provides.  `configure` scripts see what’s available and build what they can, 
and they often utilize information from pkg-config where it’s available.

I wonder *why* are you avoiding pkg-config? Are you planning to build/compile 
on a system without it?  Are you thinking of a portable `configure` script, and 
considering what to do if pkg-config is missing?  Because pkg-config came about 
to solve the problem you’re running into.  I’ve seen some debate about whether 
pkg-config solves the problem right, but it is the thing in place and trying to 
avoid it is to make yourself problems.  Not using it means a lot of extra 
trouble, so unless you have a *really* good reason...

Perette

_______________________________________________
Libav-user mailing list
[email protected]
http://ffmpeg.org/mailman/listinfo/libav-user

Reply via email to