连接ffmpeg示例源代码出现问题

3

我成功地从源代码在我的Ubuntu 11.10机器上构建了ffmpeg和libx264。

我正在尝试处理示例源文件 decoding_encoding.c。该示例附带一个makefile,因此我只需输入“make all”即可将所有内容编译链接起来。现在,我正在尝试从命令行编译和链接,但无法将其链接起来。

以下是makefile的内容:

# use pkg-config for getting CFLAGS abd LDFLAGS
FFMPEG_LIBS=libavdevice libavformat libavfilter libavcodec libswscale libavutil
CFLAGS+=$(shell pkg-config  --cflags $(FFMPEG_LIBS))
LDFLAGS+=$(shell pkg-config --libs $(FFMPEG_LIBS))

EXAMPLES=decoding_encoding filtering metadata muxing

OBJS=$(addsuffix .o,$(EXAMPLES))

%: %.o
        $(CC) $< $(LDFLAGS) -o $@

%.o: %.c
        $(CC) $< $(CFLAGS) -c -o $@

.phony: all clean

all: $(OBJS) $(EXAMPLES)

clean:
        rm -rf $(EXAMPLES) $(OBJS)

我可以使用以下方法编译源代码:
gcc -Wall -I/usr/local/include -c -o decoding_encoding.o decoding_encoding.c

当我尝试使用以下方式进行链接时:

gcc -Wall -L/usr/local/lib -lavdevice -lavformat -lavfilter -lavcodec -lswscale -lavutil -o decoding_encoding decoding_encoding.o

此时,我得到了一个大量的“未定义引用错误”列表。

decoding_encoding.o: In function `audio_encode_example':
decoding_encoding.c:(.text+0x25): undefined reference to `avcodec_find_encoder'
decoding_encoding.c:(.text+0x6a): undefined reference to `avcodec_alloc_context3'
decoding_encoding.c:(.text+0xad): undefined reference to `avcodec_open'
decoding_encoding.c:(.text+0x1ce): undefined reference to `sin'
decoding_encoding.c:(.text+0x238): undefined reference to `avcodec_encode_audio'
decoding_encoding.c:(.text+0x297): undefined reference to `avcodec_close'
decoding_encoding.c:(.text+0x2a3): undefined reference to `av_free'
decoding_encoding.o: In function `audio_decode_example':
decoding_encoding.c:(.text+0x2f7): undefined reference to `av_init_packet'
decoding_encoding.c:(.text+0x30b): undefined reference to `avcodec_find_decoder'
decoding_encoding.c:(.text+0x359): undefined reference to `avcodec_alloc_context3'
decoding_encoding.c:(.text+0x379): undefined reference to `avcodec_open'
..... etc.
collect2: ld returned 1 exit status

我在链接器命令上做错了什么吗?我检查了Makefile,我相信我正在做与Makefile完全一样的事情……或者不是吗?

谢谢,

Leo

1个回答

1

-l选项应该放在其他选项之后。


我刚刚尝试了这个命令:gcc -Wall -o decoding_encoding -L/usr/local/lib -lavdevice -lavformat -lavfilter -lavcodec -lswscale -lavutil decoding_encoding.o,结果和之前一样... - Leonard Teo
抱歉,我说得不太准确,-l选项应该放在甚至是非选项参数之后。 - tripleee
没错,就是这样。谢谢Tripleee! :) - Leonard Teo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接