2014-07-10 1 views
3

C++ 프로젝트에서 ffmpeg의 libavcodec 및 libavformat 라이브러리를 사용하고 있습니다. -lavcodec -lavformat와 g ++ 컴파일러를 연결하면 잘되지만, automake 프로젝트에서 컴파일 된 동일한 코드를 사용하려고 할 때 어떤 문제가 있는지 잘 모르겠습니다. 잘automake에서 libavcodec, libavformat을 연결하는 방법?

작업 :

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' 

은 내가 잘못 여기서 뭐하는 거지?

답변

5

CPPFLAGSCPP rocessor위한 것이다. 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> 
} 
+0

ok 제가 먼저 정적 라이브러리 (libavcodec를 포함한 소스 코드 사용)를 만든 다음 이진 파일에 연결합니다. 이제 Makefile.am의 libraryname_LDFLAGS 및 binaryname_LDFLAGS의 -lavformat -lavcodec에 대한 대답에 따라 설정했지만 여전히 정의되지 않은 참조 오류가 발생합니다. 내가 여기서 무엇을 놓치고 있니? – user2212461

+1

@ user2212461 :'-lavutil'. 또한,'make V = 1'의 COMPLETE 출력을 게시하십시오. – Cornstalks

+0

-lavutil을 링커 플래그에 추가하면 오류 알림이 제거되지 않았습니다. 내 게시물에 V = 1의 출력을 추가했습니다. – user2212461

관련 문제