与 libavcodec 链接,仍然看到未定义的引用
linking with libavcodec, still seeing undefined references
我正在尝试编译一个 libavcodec 示例。我收到以下错误:
lol@foldingmachine:~/p/avtest$ g++ main.cpp -o main -lavcodec
main.cpp: In function ‘void audio_decode_example(const char*, const char*)’:
main.cpp:57:15: warning: ‘int avcodec_decode_audio4(AVCodecContext*, AVFrame*, int*, const AVPacket*)’ is deprecated [-Wdeprecated-declarations]
len = avcodec_decode_audio4(c, decoded_frame, &got_frame, &avpkt);
^~~~~~~~~~~~~~~~~~~~~
In file included from main.cpp:1:0:
/usr/include/x86_64-linux-gnu/libavcodec/avcodec.h:4773:5: note: declared here
int avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame,
^~~~~~~~~~~~~~~~~~~~~
main.cpp:57:73: warning: ‘int avcodec_decode_audio4(AVCodecContext*, AVFrame*, int*, const AVPacket*)’ is deprecated [-Wdeprecated-declarations]
len = avcodec_decode_audio4(c, decoded_frame, &got_frame, &avpkt);
^
In file included from main.cpp:1:0:
/usr/include/x86_64-linux-gnu/libavcodec/avcodec.h:4773:5: note: declared here
int avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame,
^~~~~~~~~~~~~~~~~~~~~
/tmp/ccbXVtbs.o: In function `audio_decode_example(char const*, char const*)':
main.cpp:(.text+0x37): undefined reference to `av_init_packet(AVPacket*)'
main.cpp:(.text+0x63): undefined reference to `avcodec_find_decoder(AVCodecID)'
main.cpp:(.text+0xa4): undefined reference to `avcodec_alloc_context3(AVCodec const*)'
main.cpp:(.text+0xf1): undefined reference to `avcodec_open2(AVCodecContext*, AVCodec const*, AVDictionary**)'
main.cpp:(.text+0x19c): undefined reference to `av_free(void*)'
main.cpp:(.text+0x203): undefined reference to `av_frame_alloc()'
main.cpp:(.text+0x266): undefined reference to `avcodec_decode_audio4(AVCodecContext*, AVFrame*, int*, AVPacket const*)'
main.cpp:(.text+0x2b8): undefined reference to `av_get_bytes_per_sample(AVSampleFormat)'
main.cpp:(.text+0x460): undefined reference to `avcodec_close(AVCodecContext*)'
main.cpp:(.text+0x46c): undefined reference to `av_free(void*)'
main.cpp:(.text+0x47b): undefined reference to `av_frame_free(AVFrame**)'
collect2: error: ld returned 1 exit status
如您所见,我正在 link 使用 libavcodec
,但仍然得到未定义的引用。我还需要 link 来定义这些符号吗?
我在 IRC 上问过,答案是申请 extern "C"
。我改变了这个:
#include <libavcodec/avcodec.h>
对此:
extern "C" {
#include <libavcodec/avcodec.h>
}
在源文件中,现在编译没有错误。
我正在尝试编译一个 libavcodec 示例。我收到以下错误:
lol@foldingmachine:~/p/avtest$ g++ main.cpp -o main -lavcodec
main.cpp: In function ‘void audio_decode_example(const char*, const char*)’:
main.cpp:57:15: warning: ‘int avcodec_decode_audio4(AVCodecContext*, AVFrame*, int*, const AVPacket*)’ is deprecated [-Wdeprecated-declarations]
len = avcodec_decode_audio4(c, decoded_frame, &got_frame, &avpkt);
^~~~~~~~~~~~~~~~~~~~~
In file included from main.cpp:1:0:
/usr/include/x86_64-linux-gnu/libavcodec/avcodec.h:4773:5: note: declared here
int avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame,
^~~~~~~~~~~~~~~~~~~~~
main.cpp:57:73: warning: ‘int avcodec_decode_audio4(AVCodecContext*, AVFrame*, int*, const AVPacket*)’ is deprecated [-Wdeprecated-declarations]
len = avcodec_decode_audio4(c, decoded_frame, &got_frame, &avpkt);
^
In file included from main.cpp:1:0:
/usr/include/x86_64-linux-gnu/libavcodec/avcodec.h:4773:5: note: declared here
int avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame,
^~~~~~~~~~~~~~~~~~~~~
/tmp/ccbXVtbs.o: In function `audio_decode_example(char const*, char const*)':
main.cpp:(.text+0x37): undefined reference to `av_init_packet(AVPacket*)'
main.cpp:(.text+0x63): undefined reference to `avcodec_find_decoder(AVCodecID)'
main.cpp:(.text+0xa4): undefined reference to `avcodec_alloc_context3(AVCodec const*)'
main.cpp:(.text+0xf1): undefined reference to `avcodec_open2(AVCodecContext*, AVCodec const*, AVDictionary**)'
main.cpp:(.text+0x19c): undefined reference to `av_free(void*)'
main.cpp:(.text+0x203): undefined reference to `av_frame_alloc()'
main.cpp:(.text+0x266): undefined reference to `avcodec_decode_audio4(AVCodecContext*, AVFrame*, int*, AVPacket const*)'
main.cpp:(.text+0x2b8): undefined reference to `av_get_bytes_per_sample(AVSampleFormat)'
main.cpp:(.text+0x460): undefined reference to `avcodec_close(AVCodecContext*)'
main.cpp:(.text+0x46c): undefined reference to `av_free(void*)'
main.cpp:(.text+0x47b): undefined reference to `av_frame_free(AVFrame**)'
collect2: error: ld returned 1 exit status
如您所见,我正在 link 使用 libavcodec
,但仍然得到未定义的引用。我还需要 link 来定义这些符号吗?
我在 IRC 上问过,答案是申请 extern "C"
。我改变了这个:
#include <libavcodec/avcodec.h>
对此:
extern "C" {
#include <libavcodec/avcodec.h>
}
在源文件中,现在编译没有错误。