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'
我在做什麼錯在這裏?
ok我首先構建一個靜態庫(使用包含libavcodec的源代碼),然後將其鏈接到二進制文件。我現在根據你的回答在Makefile.am中設置libraryname_LDFLAGS和binaryname_LDFLAGS爲-lavformat -lavcodec,但仍然會得到錯誤的undefined引用。我在這裏錯過了什麼? – user2212461
@ user2212461:'-lavutil'。另外,發佈'make V = 1'的COMPLETE輸出。 – Cornstalks
將-lavutil添加到鏈接程序標誌沒有刪除錯誤通知。我在帖子中添加了make V = 1的輸出。 – user2212461