ffmpeg: undefined reference to sws_getContext and others library linking question

ffmpeg: undefined reference to sws_getContext and others library linking questionn 编译和移植过程中遇到问题的资料总结

资料来源:

http://ffmpeg.org/pipermail/ffmpeg-user/2012-July/007945.html

https://blog.csdn.net/jody1989/article/details/46660369

https://blog.csdn.net/lg1259156776/article/details/53324177

Hi Everybody, 
(sorry for inconvenence: ffmpeg-user can't receive this big email, it limited in 60KB, I just want you to see full error message)
I compiled ffmpeg-0.11.1 on linux, I want to use its library and header in a small specific c program to use av_register_all() in ffmpeg library,
I am having trouble in linking ffmpeg.

0) I use Centos 6.3 for a linux machine.
1) I have compiled ffmpeg-0.11.1 in /root/ffmpeg-source/working/ffmpeg ( I use 'configure' and 'make', not use 'make install' because i want to manage ffmpeg in a specific directory)
 ./configure --enable-gpl --enable-avfilter --enable-swscale --disable-shared --enable-libmp3lame --enable-libtheora --enable-libvo-aacenc --enable-libvorbis --enable-libvpx --enable-libx264 --    enable-version3
make

2) I make a test.c in /root/ffmpeg-source/working/test.c as below:
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include <stdio.h>
int main()
{
        avcodec_register_all();
        avfilter_register_all();
        av_register_all();
        printf("Test FFmpeg library! \n");
        return 1;
}

2.1) make a link inside working:
ln -s ../ffmpeg ffmpeg 
 
3) I make a Makefile in /root/ffmpeg-source/working/ as below:
PROGRAM = test
INCLUDEDIRS = -Iffmpeg/

LIBDIRS = \
        -L./ffmpeg/libavcodec \
        -L./ffmpeg/libavformat \
        -L./ffmpeg/libavfilter \
        -L./ffmpeg/libpostproc \
        -L./ffmpeg/libswresample \
        -L./ffmpeg/libswscale \
        -L./ffmpeg/libavdevice \
        -L./ffmpeg/libavutil

LIBS = -lpostproc -lswresample -lswscale -lavfilter -lavdevice -lavformat -lavcodec -lavutil -lm -ldl -Wl
 
CXXSOURCES = test.c               
CXXOBJECTS = $(CXXSOURCES:.c=.o)  
HEADERFLAGS = $(INCLUDEDIRS)
CXX = gcc
LDFLAGS = $(LIBDIRS) $(LIBS)

all: $(PROGRAM)
$(PROGRAM): $(CXXOBJECTS)
        $(CXX) -o $@ $(CXXOBJECTS) $(LDFLAGS)
test.o: test.c
        $(CXX) $(HEADERFLAGS) -c -o test.o test.c
clean:
        $(RM) -f $(CXXOBJECTS) $(PROGRAM)

=> When I compile:
[root at CENT6 working]# make
gcc -Iffmpeg/  -c -o test.o test.c
gcc -o test test.o   -L./ffmpeg/libavcodec -L./ffmpeg/libavformat -L./ffmpeg/libavfilter -L./ffmpeg/libpostproc -L./ffmpeg/libswresample -L./ffmpeg/libswscale -L./ffmpeg/libavdevice -L./ffmpeg/libavutil  -lpostproc -lswresample -lswscale -lavfilter -lavdevice -lavformat -lavcodec -lavutil -lm -ldl -Wl
./ffmpeg/libavfilter/libavfilter.a(vf_mp.o): In function `sws_getContextFromCmdLine':
/root/ffmpeg-source/ffmpeg/libavfilter/vf_mp.c:324: undefined reference to `sws_getContext'
./ffmpeg/libavfilter/libavfilter.a(vf_scale.o): In function `config_props':
........ 编译报错信息请参照原文,有完整的记录
collect2: ld returned 1 exit status
make: *** [test] Error 1


解决办法

转自     https://blog.csdn.net/jody1989/article/details/46660369

2) 错误提示:
/opt/.../lib/libavcodec.a(pthread.o): In function `avcodec_thread_free':
/opt/.../libavcodec/pthread.c:95: undefined reference to `pthread_join'
解决:
编译时加链接linux的多线程库 "-lpthread"
# gcc output_example.c -o output_example 
-I/opt/.../include 
-L/opt/.../lib  
-lavcodec -lavdevice -lavfilter -lavformat -lavutil -lswscale
-lm -lpthread

转自    https://blog.csdn.net/lg1259156776/article/details/53324177

后来查阅ffmpeg的 pkg-config,终于找到原因,错误导致过程让我痛苦,原因却很简单。

错误:gcc  test.c -o test -I/GA/gabin/include/ -L/GA/gabin/lib  -lavcodec -lavformat  -lavdevice -lavutil -pthread  -ldl -lswscale -lSDL -lbz2  -lasound -lz -lm  

调整: gcc  test.c -o test -I/GA/gabin/include/ -L/GA/gabin/lib  -lavformat  -lavdevice -lavcodec  -lavutil -pthread  -ldl -lswscale -lSDL -lbz2  -lasound -lz -lm  

问题解决,同志需要注意包依赖关系。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值