[Libav-user] Can not link ffmpeg without pkg-config

Javier Lopez jlopez2022 at gmail.com
Mon Aug 29 10:36:13 EEST 2016


I installed the ffmpeg library following
https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu
on a Debian computer, but I could not compile or link.
Then I installed the ffmpeg at usr/local accordingly:
https://trac.ffmpeg.org/wiki/How%20to%20quickly%20compile%20FFmpeg%20with%20opus%20and%20x264

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?

code:

#include <stdio.h>
#ifndef inline
#define inline __inline
#endif
#ifndef UINT64_C
#define UINT64_C uint64_t
#define INT64_C int64_t
#endif//end extern "C"
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
//Avoid undefined PIX_FMT_RGB24
#ifndef PIX_FMT_RGB24
#define PIX_FMT_RGB24 AV_PIX_FMT_RGB24
#endif
// compatibility with newer API
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,28,1)
#define av_frame_alloc avcodec_alloc_frame
#define av_frame_free avcodec_free_frame
#endif


int main(int argc, char *argv[])
{
  av_register_all();
  return 0;
}


Here are a lot of command line failing trials:
Do not compiles under linux:
gcc -o ffmpeg_grabber ffmpeg_grabber.c -I/home/acciona/ffmpeg_build/include
-lavutil -lavformat -lavcodec -lz -lm
gcc -o ffmpeg_grabber ffmpeg_grabber.c
-I/home/acciona/ffmpeg_build/include  -I/home/acciona/ffmpeg_build/lib
-llibavutil -llibavformat -llibavcodec -lz -lm
gcc -o ffmpeg_grabber ffmpeg_grabber.c
-I/home/acciona/ffmpeg_build/include
"/home/acciona/ffmpeg_build/lib/libavutil.a"
"/home/acciona/ffmpeg_build/lib/libavformat.a"
"/home/acciona/ffmpeg_build/lib/libavcodec.a" -lz -lm
gcc -o ffmpeg_grabber ffmpeg_grabber.c
-I/home/acciona/ffmpeg_build/include  -L/home/acciona/ffmpeg_build/lib
libavutil.a libavformat.a libavcodec.a -lz -lm
Compiles but fail links:
gcc -o ffmpeg_grabber ffmpeg_grabber.c
-I/home/acciona/ffmpeg_build/include  -L/home/acciona/ffmpeg_build/lib
-lavutil -lavformat -lavcodec -lz -lm
gcc -Wall -g ffmpeg_grabber.c -o ffmpeg_grabber
-I/home/acciona/ffmpeg_build/include
/home/acciona/ffmpeg_build/lib/libswscale.a
/home/acciona/ffmpeg_build/lib/libavdevice.a
/home/acciona/ffmpeg_build/lib/libavformat.a
/home/acciona/ffmpeg_build/lib/libavcodec.a
/home/acciona/ffmpeg_build/lib/libavutil.a   -lpthread  -lm -lz  -lmp3lame
-lx264
Linker errors (undefined a lot of things)
gcc -Wall -g ffmpeg_grabber.c -o ffmpeg_grabber
-I/home/acciona/ffmpeg_build/include  -L/home/acciona/ffmpeg_build/lib
-lswscale   -lavdevice  -lavformat  -lavcodec   -lavutil   -lpthread  -lm
-lz  -lmp3lame -lx264

Few link errors (not find av_*):
gcc -o ffmpeg_grabber ffmpeg_grabber.c
-I/home/acciona/ffmpeg_build/include $(pkg-config --cflags --libs
-L/home/acciona/ffmpeg_build/lib libavdevice libavformat libavcodec
libavutil) -lpthread -lm -lz -lmp3lame -lx264
gcc -o ffmpeg_grabber ffmpeg_grabber.c
-I/home/acciona/ffmpeg_build/include $(pkg-config --cflags --libs
-L/home/acciona/ffmpeg_build/lib libswscale libavdevice libavformat
libavcodec libavutil) -lpthread -lm -lz -lmp3lame -lx264
gcc -I/home/acciona/ffmpeg_build/include $(pkg-config --cflags --libs
-L/home/acciona/ffmpeg_build/lib libswscale libavdevice libavformat
libavcodec libavutil) -lpthread -lm -lz -lmp3lame -lx264 -o ffmpeg_grabber
ffmpeg_grabber.c
gcc -I/home/acciona/ffmpeg_build/include $(pkg-config --cflags --libs
libswscale libavdevice libavformat libavcodec libavutil -lpthread -lm -lz
-lmp3lame -lx264 -o ffmpeg_grabber ffmpeg_grabber01.c

gcc  -lswscale -lavdevice -lavformat -lavcodec -lavutil -lpthread -lm -lz
-lmp3lame -lx264 -o ffmpeg_grabber ffmpeg_grabber_01.c
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20160829/be91d8da/attachment.html>


More information about the Libav-user mailing list