ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

c – 如何在automake中链接libavcodec,libavformat?

2019-08-30 18:06:35  阅读:250  来源: 互联网

标签:libtool automake c ffmpeg makefile


我在C项目中使用来自ffmpeg的libavcodec和libavformat库.链接-lavcodec -lavformat与g编译器工作正常,但我不确定当我尝试使用在automake项目中编译的相同代码时出了什么问题.

工作正常:

g++ -o test -D__STDC_CONSTANT_MACROS -lavcodec -lavformat test.cpp

不工作Makefile.am:

binaryname_LDFLAGS= -lavcodec -lavformat

错误:

....
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/libavformat.a(nut.o):function 
ff_nut_add_sp: error: undefined reference to 'av_tree_node_size'
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/libavformat.a(nut.o):function 
ff_nut_add_sp: error: undefined reference to 'av_tree_insert'
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/libavformat.a(nut.o):function 
ff_nut_free_sp: error: undefined reference to 'av_tree_enumerate'
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/libavformat.a(nut.o):function 
ff_nut_free_sp: error: undefined reference to 'av_tree_destroy'
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/libavformat.a(rtp.o):function 
ff_rtp_get_payload_type: error: undefined reference to 'av_opt_get_int'
...

也没工作:

LDFLAGS=...-lavcodec -lavformat

错误:

src/dsp/audioDecoder.cpp:99: error: undefined reference to 'av_register_all'
src/dsp/audioDecoder.cpp:101: error: undefined reference to 'avcodec_find_decoder'
src/dsp/audioDecoder.cpp:109: error: undefined reference to 'avcodec_alloc_context'
src/dsp/audioDecoder.cpp:120: error: undefined reference to 'avcodec_open2'
src/dsp/audioDecoder.cpp:125: error: undefined reference to 'av_init_packet'
src/dsp/audioDecoder.cpp:188: error: undefined reference to 'avcodec_decode_audio3'

在第二种情况下,如果我没有设置任何链接器,则无法找到包含头,因此链接器似乎以某种方式被识别.

使V = 1返回:

make  all-am
make[1]: Go to '/path/to/trunk'
/bin/bash ./libtool --tag=CXX   --mode=link g++  -O2 -lrt -D__STDC_CONSTANT_MACROS   -o binaryname progsrc/binaryname/binaryname-binaryname.o    -lm  -lpthread -ldl -lmygeneratedlibrary
libtool: link: g++ -O2 -D__STDC_CONSTANT_MACROS -o binaryname progsrc/binaryname/binaryname-binaryname.o  -lm /path/to//trunk/.libs/lmygeneratedlibrary.a -lrt -lavutil -lavcodec -lavformat -lpthread -ldl
make[1]: Leave '/path/to/trunk'

我在这做错了什么?

解决方法:

CPPFLAGS用于C预处理器.不是C标志.这是CXXFLAGS.对于链接器的东西,你想要LDFLAGS.

您的Makefile.am似乎不遵循规范的Makefile.am格式.你可能想要它更像(taken from here):

# what flags you want to pass to the C compiler & linker
CFLAGS = # C compiler flags
LDFLAGS = # Linker flags

# this lists the binaries to produce, the (non-PHONY, binary) targets in
# the previous manual Makefile
bin_PROGRAMS = targetbinary1 targetbinary2 [...] targetbinaryN
targetbinary1_SOURCES = targetbinary1.c myheader.h [...]
targetbinary2_SOURCES = targetbinary2.c
.
.
targetbinaryN_SOURCES = targetbinaryN.c

此外,请确保在包含FFmpeg的标题时,用extern“C”包围它们.例如:

extern "C" {
#include <libavformat/avformat.h>
}

标签:libtool,automake,c,ffmpeg,makefile
来源: https://codeday.me/bug/20190830/1769729.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有