2012-04-12 13 views
4

の「avcodoec_open2」に0.8から「ffmpegのバージョンのgit-2012-04-12-277f20c」にFFMPEGライブラリを更新した後、私のC++プログラムのいずれかをコンパイルするとき、私はエラーが発生しているFFMPEG未定義のリファレンスはC++

エラー私は次のように私のプログラムがある作るとき、私は得る:

-------- begin -------- 
Linking: Analysing_Server 
./source/Encoding_Thread.o: In function `CEncoding_Thread::do_work()': 
/home/Analyser/source/Encoding_Thread.cpp:155: undefined reference to `avcodec_open2' 
collect2: ld returned 1 exit status 
make: *** [Analysing_Server] Error 1 

私のメイクファイルの関連行は以下のようにG ++を実行するのに似ている:Aは、私の関連するCPPコのバージョンをストリップダウン

g++ test2.cpp -lavformat -lavcodec -lavutil -D__STDC_CONSTANT_MACROS 

エラーをスロードは次のようになります。それが使用するすべての機能が、今減価償却されているので、作品はもはやFFMPEGが付属しています「のdoc /例/ decoding_encoding.c」下

#include <stdio.h> 
#include <stdint.h> 

#define LOG_OUT_STREAM_BUFF_SIZE 200000 


extern "C" { 
    /* The ffmpeg library is completely written in C, so we need to tell the C++ compiler that so it links correctly. */ 
    #include "stdint.h" 
    #include "libavcodec/avcodec.h" 
    #include "libavutil/mathematics.h" 
    #include "libswscale/swscale.h" 
    #include "libavfilter/avfilter.h" 

    int avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVDictionary **options); 
    int avcodec_encode_video2(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr); 
} 

uint8_t m_outbuf[2][LOG_OUT_STREAM_BUFF_SIZE]; 
unsigned int m_out_size[2]; 
unsigned int m_OutBuffer_ID[2]; 
unsigned int m_Buffer_ID; /* This is just a uniqueish stamp we give to each buffer so we can tell when they change.. */ 

AVCodecContext * m_CodecContex; 
AVCodec * m_codec; 
struct SwsContext *m_img_convert_ctx; 

unsigned char* m_DataBuff; 

int Output_Width, Output_Height; 
int Output_Bitrate; 


int main(void) { 
    //New version of FFMPEG calls this in avcodec_register_all 
    //avcodec_init(); 

    /* register all the codecs */ 
    avcodec_register_all(); 

    /* Initalise the encoder */ 
    m_codec = avcodec_find_encoder(CODEC_ID_MP2); 

    if (!m_codec) { 
    printf("Encoding codec not found\n"); 
    } 

    /* init the pointers.. */ 
    m_CodecContex = NULL; 

    /* Default values.. */ 
    Output_Width = 1600; 
    Output_Height = 1200; 
    Output_Bitrate = 600000; 

    /* Create/setup the Codec details.. */ 
    //Changed to work with new FFMPEG 
    m_CodecContex = avcodec_alloc_context3(m_codec); 
    avcodec_get_context_defaults3(m_CodecContex, m_codec); 

    /* put sample parameters */ 
    m_CodecContex->bit_rate = Output_Bitrate; 
    /* resolution must be a multiple of two */ 

    m_CodecContex->width = Output_Width; 
    m_CodecContex->height = Output_Height; 
    /* frames per second */ 
    m_CodecContex->time_base= (AVRational){1,25}; 

    m_CodecContex->gop_size = 10; /* emit one intra frame every ten frames */ 
    m_CodecContex->max_b_frames=1; 
    m_CodecContex->pix_fmt = PIX_FMT_YUV420P; /* must be YUV for encoding.. */ 


    AVDictionary * RetunedAVDic; 

    /* open it */ 
    //Changed to work with new FFMPEG 
    if (avcodec_open2(m_CodecContex, m_codec, &RetunedAVDic) < 0) { 
     printf("could not open codec"); 
    } 
} 

残念ながら、例。私のコードは、サンプルコードに基づいてFFMPEG 0.8で正常に動作しましたが、FFMPEGの最新バージョンではコンパイルされません。減価償却された関数の一部を新しいバージョンに変更しましたが、それでもコンパイルは行われません。

なぜこのエラーが発生するのですか?誰かがFFMPEGの最新版を使って 'doc/examples/decoding_encoding.c'のような例へのリンクを持っていますか?

+1

nm -D /usr/lib/libavcodec.so.52を実行すると、私のシステムにインストールされている 'libavcodec'の' grep avcodec_open'を実行すると、 '00000000002e4a80 T avcodec_open' - no' avcodec_open2'という出力が表示されます。あなたはこのシンボルが利用可能であると確信していますか?あなた(そして私)がインストールしたより新しいバージョンまたは古いバージョンの 'libavcodec'が必要ですか? – sarnold

+0

なぜ 'avcodec_open2()'と 'avcodec_encode_video2()'をコンパイラが 'avcodec.h 'にある宣言を使うのではなく、あなたのコードに手動で定義していますか? –

+0

sarnold、私はもともとavcodec_openを使用していましたが、avcodec.hのコメントでavcodec_open2を代わりに使用しています。私がavcodec_openを試してみると、コードはコンパイルされますが、コーデックを開くことができません。これはFFMPEG 0.8で動作していました。 FFMPEGの最新バージョンをインストールしたばかりですが、FFMPEGの最新バージョンにロールバックできるかどうか試してみるかもしれません。 Remy、私はC++でCライブラリを使用するときに手動で関数を定義しなければならないかもしれないところを読んでいます。これらの2行のコードを削除すると、同じエラーが発生します。 – ALM865

答えて

1

私のメイクファイルの関連行は以下のようにG ++実行するのと似ています。プログラミングで

g++ test2.cpp -lavformat -lavcodec -lavutil -D__STDC_CONSTANT_MACROS

  1. を、詳細はを問題では。あなたのリンクコマンドはではなく、上記のコマンドと十分に似ていないか、それともうまくいったでしょうか。
  2. リンク線の間違った場所にライブラリを置いている可能性があります。ソースとライブラリの順序はmattersです。

更新:

はあなたがCPPファイルに上記の付属のコードを入れた場合は、G ++付属のオプションで実行し、それが動作しません。 "avcodec_open2 'への未定義の参照エラーが発生します。

いいえ、私はしません。私は別のエラーが出ます(私はavcodecが全くインストールされていないので)。

のコマンド例では、すでにあなたのために失敗した場合、あなたはそれがが生成エラー、いくつかの他のコマンドからのエラーではなくを提供しなければならないので、我々はそのコマンドは、ように見えたかもしれないものを推測する必要はありません。

ライブラリの順序は、FFMPEGバージョン0.8で動作しましたが、なぜ最新バージョンでは機能しませんか?あなたは、最新のlibavcodec54をインストールしましたが、最新のlibavcodec-devをインストールしていないおそらくので

+0

1.上記のコードをCPPファイルに入れ、付属のオプションでg ++を実行すると、動作しません。 "avcodec_open2 'への未定義の参照エラーが発生します。 2.ライブラリの順序は、FFMPEGバージョン0.8で動作しましたが、なぜ最新バージョンでは機能しませんか?私は図書館が正しい順序であると信じています。 – ALM865