2011-06-22 25 views
2

私はH264パーサー(OOなし)を作成していますが、いくつかのモジュールを使ってより良いものを整理しようとしています。多重定義[...]ここで最初に定義します

私はこの問題を抱えている:

`CMakeFiles/server.dir/mainclass.cpp.o:(.bss+0x0): multiple definition of `I_Macroblock_Modes' 
`CMakeFiles/server.dir/main.cpp.o:(.bss+0x0): first defined here 
`CMakeFiles/server.dir/mainclass.cpp.o:(.bss+0x300): multiple definition of `P_and_SP_macroblock_modes' 
`CMakeFiles/server.dir/main.cpp.o:(.bss+0x300): first defined here 
`CMakeFiles/server.dir/mainclass.cpp.o:(.bss+0x680): multiple definition of `B_Macroblock_Modes' 
`CMakeFiles/server.dir/main.cpp.o:(.bss+0x680): first defined here 
`CMakeFiles/server.dir/thRunAppl.cpp.o:(.bss+0x0): multiple definition of `I_Macroblock_Modes' 
`CMakeFiles/server.dir/main.cpp.o:(.bss+0x0): first defined here 
`CMakeFiles/server.dir/thRunAppl.cpp.o:(.bss+0x300): multiple definition of `P_and_SP_macroblock_modes' 
`CMakeFiles/server.dir/main.cpp.o:(.bss+0x300): first defined here 
`CMakeFiles/server.dir/thRunAppl.cpp.o:(.bss+0x680): multiple definition of `B_Macroblock_Modes' 
`CMakeFiles/server.dir/main.cpp.o:(.bss+0x680): first defined here 
`CMakeFiles/server.dir/h.264parser.cpp.o:(.bss+0x0): multiple definition of `I_Macroblock_Modes' 
`CMakeFiles/server.dir/main.cpp.o:(.bss+0x0): first defined here 
`CMakeFiles/server.dir/h.264parser.cpp.o:(.bss+0x300): multiple definition of `P_and_SP_macroblock_modes' 
`CMakeFiles/server.dir/main.cpp.o:(.bss+0x300): first defined here 
`CMakeFiles/server.dir/h.264parser.cpp.o:(.bss+0x680): multiple definition of `B_Macroblock_Modes' 
`CMakeFiles/server.dir/main.cpp.o:(.bss+0x680): first defined here 
`CMakeFiles/server.dir/moc_mainclass.cxx.o:(.bss+0x0): multiple definition of `I_Macroblock_Modes' 
`CMakeFiles/server.dir/main.cpp.o:(.bss+0x0): first defined here 
`CMakeFiles/server.dir/moc_mainclass.cxx.o:(.bss+0x300): multiple definition of `P_and_SP_macroblock_modes' 
`CMakeFiles/server.dir/main.cpp.o:(.bss+0x300): first defined here 
`CMakeFiles/server.dir/moc_mainclass.cxx.o:(.bss+0x680): multiple definition of `B_Macroblock_Modes' 
`CMakeFiles/server.dir/main.cpp.o:(.bss+0x680): first defined here 
`CMakeFiles/server.dir/moc_thRunAppl.cxx.o:(.bss+0x0): multiple definition of `I_Macroblock_Modes' 
`CMakeFiles/server.dir/main.cpp.o:(.bss+0x0): first defined here 
`CMakeFiles/server.dir/moc_thRunAppl.cxx.o:(.bss+0x300): multiple definition of `P_and_SP_macroblock_modes' 
`CMakeFiles/server.dir/main.cpp.o:(.bss+0x300): first defined here 
`CMakeFiles/server.dir/moc_thRunAppl.cxx.o:(.bss+0x680): multiple definition of `B_Macroblock_Modes' 
`CMakeFiles/server.dir/main.cpp.o:(.bss+0x680): first defined here 
`CMakeFiles/server.dir/h.264parser.cpp.o: In function `MbPartPredMode(int, int)': 
`h.264parser.cpp:(.text+0xf0): undefined reference to `B_macroblockmodes(int, int)' 
`h.264parser.cpp:(.text+0x104): undefined reference to `B_macroblockmodes(int, int)' 
`h.264parser.cpp:(.text+0x111): undefined reference to `I_macroblockmodes(int, int)' 
`h.264parser.cpp:(.text+0x124): undefined reference to `P_and_SP_macroblockmodes(int, int)' 
`h.264parser.cpp:(.text+0x134): undefined reference to `P_and_SP_macroblockmodes(int, int)' 

私のシナリオは次のとおりです。

macroblocktypes.h。

#include "macroblocktypes.h" 

int I_Macroblock_Modes[27][7]; 
int P_and_SP_macroblock_modes[32][7]; 
int B_Macroblock_Modes[50][7]; 

int I_macroblockmodes(int line, int column); 
int P_and_SP_macroblockmodes(int line, int column); 
int B_macroblockmodes(int line, int column); 

macroblocktables.cpp、.hファイルの各配列と機能のために、このような定義された配列との機能を有する:ちょうど定義

macroblocktables.h有します。

#include "macroblocktables.h" 
int I_macroblock_modes[27][7] ={ 
{0, I_4x4, 0, Intra_4x4, NA, NA, NA}, 
//If this line was to be commented out, the MbPartPredMode macro would have to be changed 
//since it relies on the linear rise of the value in the first column. 
//{0, I_NxN,   1, Intra_8x8, NA, NA, NA}, 
{1, I_16x16_0_0_0, NA, Intra_16x16, 0, 0, 0}, 
{2, I_16x16_1_0_0, NA, Intra_16x16, 1, 0, 0}, 
{3, I_16x16_2_0_0, NA, Intra_16x16, 2, 0, 0}, 
{4, I_16x16_3_0_0, NA, Intra_16x16, 3, 0, 0}, 
{5, I_16x16_0_1_0, NA, Intra_16x16, 0, 1, 0}, 
{6, I_16x16_1_1_0, NA, Intra_16x16, 1, 1, 0}, 
{7, I_16x16_2_1_0, NA, Intra_16x16, 2, 1, 0}, 
{8, I_16x16_3_1_0, NA, Intra_16x16, 3, 1, 0}, 
{9, I_16x16_0_2_0, NA, Intra_16x16, 0, 2, 0}, 
{10, I_16x16_1_2_0, NA, Intra_16x16, 1, 2, 0}, 
{11, I_16x16_2_2_0, NA, Intra_16x16, 2, 2, 0}, 
{12, I_16x16_3_2_0, NA, Intra_16x16, 3, 2, 0}, 
{13, I_16x16_0_0_1, NA, Intra_16x16, 0, 0, 15}, 
{14, I_16x16_1_0_1, NA, Intra_16x16, 1, 0, 15}, 
{15, I_16x16_2_0_1, NA, Intra_16x16, 2, 0, 15}, 
{16, I_16x16_3_0_1, NA, Intra_16x16, 3, 0, 15}, 
{17, I_16x16_0_1_1, NA, Intra_16x16, 0, 1, 15}, 
{18, I_16x16_1_1_1, NA, Intra_16x16, 1, 1, 15}, 
{19, I_16x16_2_1_1, NA, Intra_16x16, 2, 1, 15}, 
{20, I_16x16_3_1_1, NA, Intra_16x16, 3, 1, 15}, 
{21, I_16x16_0_2_1, NA, Intra_16x16, 0, 2, 15}, 
{22, I_16x16_1_2_1, NA, Intra_16x16, 1, 2, 15}, 
{23, I_16x16_2_2_1, NA, Intra_16x16, 2, 2, 15}, 
{24, I_16x16_3_2_1, NA, Intra_16x16, 3, 2, 15}, 
{25, I_PCM, NA, NA, NA, NA, NA}}; 

int P_and_SP_macroblock_modes[32][7] = { 
{0, P_L0_16x16, 1, Pred_L0, NA, 16, 16}, 
{1, P_L0_L0_16x8, 2, Pred_L0, Pred_L0, 16, 8}, 
{2, P_L0_L0_8x16, 2, Pred_L0, Pred_L0, 8, 16}, 
{3, P_8x8, 4, NA, NA, 8, 8}, 
{4, P_8x8ref0, 4, NA, NA, 8, 8}, 
{0, I_4x4, 0, Intra_4x4, NA, NA, NA}, 
{1, I_16x16_0_0_0, NA, Intra_16x16, 0, 0, 0}, 
{2, I_16x16_1_0_0, NA, Intra_16x16, 1, 0, 0}, 
{3, I_16x16_2_0_0, NA, Intra_16x16, 2, 0, 0}, 
{4, I_16x16_3_0_0, NA, Intra_16x16, 3, 0, 0}, 
{5, I_16x16_0_1_0, NA, Intra_16x16, 0, 1, 0}, 
{6, I_16x16_1_1_0, NA, Intra_16x16, 1, 1, 0}, 
{7, I_16x16_2_1_0, NA, Intra_16x16, 2, 1, 0}, 
{8, I_16x16_3_1_0, NA, Intra_16x16, 3, 1, 0}, 
{9, I_16x16_0_2_0, NA, Intra_16x16, 0, 2, 0}, 
{10, I_16x16_1_2_0, NA, Intra_16x16, 1, 2, 0}, 
{11, I_16x16_2_2_0, NA, Intra_16x16, 2, 2, 0}, 
{12, I_16x16_3_2_0, NA, Intra_16x16, 3, 2, 0}, 
{13, I_16x16_0_0_1, NA, Intra_16x16, 0, 0, 15}, 
{14, I_16x16_1_0_1, NA, Intra_16x16, 1, 0, 15}, 
{15, I_16x16_2_0_1, NA, Intra_16x16, 2, 0, 15}, 
{16, I_16x16_3_0_1, NA, Intra_16x16, 3, 0, 15}, 
{17, I_16x16_0_1_1, NA, Intra_16x16, 0, 1, 15}, 
{18, I_16x16_1_1_1, NA, Intra_16x16, 1, 1, 15}, 
{19, I_16x16_2_1_1, NA, Intra_16x16, 2, 1, 15}, 
{20, I_16x16_3_1_1, NA, Intra_16x16, 3, 1, 15}, 
{21, I_16x16_0_2_1, NA, Intra_16x16, 0, 2, 15}, 
{22, I_16x16_1_2_1, NA, Intra_16x16, 1, 2, 15}, 
{23, I_16x16_2_2_1, NA, Intra_16x16, 2, 2, 15}, 
{24, I_16x16_3_2_1, NA, Intra_16x16, 3, 2, 15}, 
{25, I_PCM, NA, NA, NA, NA, NA}, 
{NA, P_Skip, 1, Pred_L0, NA, 16, 16}}; 

int B_macroblock_modes[50][7] = { 
{0, B_Direct_16x16, NA, Direct, NA, 8, 8}, 
{1, B_L0_16x16, 1, Pred_L0, NA, 16, 16}, 
{2, B_L1_16x16, 1, Pred_L1, NA, 16, 16}, 
{3, B_Bi_16x16, 1, BiPred, NA, 16, 16}, 
{4, B_L0_L0_16x8, 2, Pred_L0, Pred_L0, 16, 8}, 
{5, B_L0_L0_8x16, 2, Pred_L0, Pred_L0, 8, 16}, 
{6, B_L1_L1_16x8, 2, Pred_L1, Pred_L1, 16, 8}, 
{7, B_L1_L1_8x16, 2, Pred_L1, Pred_L1, 8, 16}, 
{8, B_L0_L1_16x8, 2, Pred_L0, Pred_L1, 16, 8}, 
{9, B_L0_L1_8x16, 2, Pred_L0, Pred_L1, 8, 16}, 
{10, B_L1_L0_16x8, 2, Pred_L1, Pred_L0, 16, 8}, 
{11, B_L1_L0_8x16, 2, Pred_L1, Pred_L0, 8, 16}, 
{12, B_L0_Bi_16x8, 2, Pred_L0, BiPred, 16, 8}, 
{13, B_L0_Bi_8x16, 2, Pred_L0, BiPred, 8, 16}, 
{14, B_L1_Bi_16x8, 2, Pred_L1, BiPred, 16, 8}, 
{15, B_L1_Bi_8x16, 2, Pred_L1, BiPred, 8, 16}, 
{16, B_Bi_L0_16x8, 2, BiPred, Pred_L0, 16, 8}, 
{17, B_Bi_L0_8x16, 2, BiPred, Pred_L0, 8, 16}, 
{18, B_Bi_L1_16x8, 2, BiPred, Pred_L1, 16, 8}, 
{19, B_Bi_L1_8x16, 2, BiPred, Pred_L1, 8, 16}, 
{20, B_Bi_Bi_16x8, 2, BiPred, BiPred, 16, 8}, 
{21, B_Bi_Bi_8x16, 2, BiPred, BiPred, 8, 16}, 
{22, B_8x8, 4, NA, NA, 8, 8}, 
{0, I_4x4, 0, Intra_4x4, NA, NA, NA}, 
{1, I_16x16_0_0_0, NA, Intra_16x16, 0, 0, 0}, 
{2, I_16x16_1_0_0, NA, Intra_16x16, 1, 0, 0}, 
{3, I_16x16_2_0_0, NA, Intra_16x16, 2, 0, 0}, 
{4, I_16x16_3_0_0, NA, Intra_16x16, 3, 0, 0}, 
{5, I_16x16_0_1_0, NA, Intra_16x16, 0, 1, 0}, 
{6, I_16x16_1_1_0, NA, Intra_16x16, 1, 1, 0}, 
{7, I_16x16_2_1_0, NA, Intra_16x16, 2, 1, 0}, 
{8, I_16x16_3_1_0, NA, Intra_16x16, 3, 1, 0}, 
{9, I_16x16_0_2_0, NA, Intra_16x16, 0, 2, 0}, 
{10, I_16x16_1_2_0, NA, Intra_16x16, 1, 2, 0}, 
{11, I_16x16_2_2_0, NA, Intra_16x16, 2, 2, 0}, 
{12, I_16x16_3_2_0, NA, Intra_16x16, 3, 2, 0}, 
{13, I_16x16_0_0_1, NA, Intra_16x16, 0, 0, 15}, 
{14, I_16x16_1_0_1, NA, Intra_16x16, 1, 0, 15}, 
{15, I_16x16_2_0_1, NA, Intra_16x16, 2, 0, 15}, 
{16, I_16x16_3_0_1, NA, Intra_16x16, 3, 0, 15}, 
{17, I_16x16_0_1_1, NA, Intra_16x16, 0, 1, 15}, 
{18, I_16x16_1_1_1, NA, Intra_16x16, 1, 1, 15}, 
{19, I_16x16_2_1_1, NA, Intra_16x16, 2, 1, 15}, 
{20, I_16x16_3_1_1, NA, Intra_16x16, 3, 1, 15}, 
{21, I_16x16_0_2_1, NA, Intra_16x16, 0, 2, 15}, 
{22, I_16x16_1_2_1, NA, Intra_16x16, 1, 2, 15}, 
{23, I_16x16_2_2_1, NA, Intra_16x16, 2, 2, 15}, 
{24, I_16x16_3_2_1, NA, Intra_16x16, 3, 2, 15}, 
{25, I_PCM, NA, NA, NA, NA, NA}, 
{NA, B_Skip, NA, Direct, NA, 8, 8}}; 

int I_macroblockmodes(int line, int column) { 
if (line < 27 && column < 7) 
    return I_macroblock_modes[line][column]; 
else { 
    if (line >= 27) { 
     return -10000; //line is bigger than the array size 
    } else { 
     return -20000; //column is bigger than the array size 
    } 
}} 
//Inter prediction slices - Macroblock types 
//Defined strictly by norm, page 121. 

//(Table 7-13 Macroblock type values 0 to 4 for P and SP slices) 
/* 
First column: mb_type 
Second column: Name of mb_type 
Third column: NumMbPart(mb_type) 
Fourth column: MbPartPredMode(mb_type, 0) 
Fifth column: MbPartPredMode(mb_type, 1) 
Sixth column: MbPartWidth(mb_type) 
Seventh column: MbPartHeight(mb_type) 
*/ 
int P_and_SP_macroblockmodes(int line, int column){ 
if (line < 32 && column < 7) 
    return P_and_SP_macroblock_modes[line][column]; 
else { 
    if (line >= 32) { 
     return -10000; //line is bigger than the array size 
    } else { 
     return -20000; //column is bigger than the array size 
    } 
}} 



//p94. Table 7-14 – Macroblock type values 0 to 22 for B slices 
/* 
First column: mb_type 
Second column: Name of mb_type 
Third column: NumMbPart(mb_type) 
Fourth column: MbPartPredMode(mb_type, 0) 
Fifth column: MbPartPredMode(mb_type, 1) 
Sixth column: MbPartWidth(mb_type) 
Seventh column: MbPartHeight(mb_type) 
*/ 
int B_macroblockmodes(int line, int column){ 
if (line < 50 && column < 7) 
    return B_macroblock_modes[line][column]; 
else { 
    if (line >= 50) { 
     return -10000; //line is bigger than the array size 
    } else { 
     return -20000; //column is bigger than the array size 
    } 
}} 

最後に私のh.264ファイル(.cppと.h)。 Imは.hにmacroblocktable.hとmacroblocktype.h、そしてh.264.cppにはh.264.hだけを含んでいます。

h.264.cppのmacroblocktable.cppの関数を使いたいと思います。事前

答えて

8

おかげであなたは任意のリンカーエラーを取得する必要がないようにあなたは、.hファイルで宣言のみではなく、定義を維持する必要があります。これら

int I_Macroblock_Modes[27][7]; 
int P_and_SP_macroblock_modes[32][7]; 
int B_Macroblock_Modes[50][7]; 

は、定義されているように見えるかもしれません。

extern int I_Macroblock_Modes[27][7]; 
extern int P_and_SP_macroblock_modes[32][7]; 
extern int B_Macroblock_Modes[50][7]; 

にこれらを変更し、あなたはそれが「単なる定義」ではありません

+0

感謝を私はしたいが、外のアレイにアクセスいけないが、一種のmacroblocktable.cppで、その後カプセル化し、呼び出しますその.cppからの関数。私は.hから宣言を削除し、 '多重定義'エラーは停止します。私はまだh.264parser.cppを持っています:(。テキスト+ 0x104):h.265.cppから関数を呼び出そうとすると、 'B_macroblockmodes(int、int) 'の定義されていない参照がエラーになります。 =( –

+0

@Pmdusso:どこからでも宣言を削除する必要はありません。以下の手順に従います。1).hファイルで、配列宣言に 'extern'キーワードを追加します。 cppファイル内の配列定義はそのままの状態にしておきます。 2)macroblocktable.cppにB_macroblockmodes(int、int)を書き込むことを意味するならば、cppファイルに 'B_macroblockmodes(int、int)'関数の定義を追加してください(あなたは本体を書くことを忘れてしまったため、エラーです。) –

+0

、やった!あなたは質問で見ることができます...そして、私は配列の定義をexternでmacroblocktable.hに書き戻しました、ありがとう! –

4

問題ないはずです。あなたはその中に変数を宣言していますので、それが含まれるたびにグローバル変数を再宣言します。

何がしたいことは、あなたが入れなければならないmacroblocktables.hヘッダに、他の.C /の.cppファイルからI_Macroblock_Modesにアクセスする場合:これらは配列がmacroblocktables.cppで定義されているint型なので

//resides in macroblocktables.cpp 
extern int I_Macroblock_Modes[27][7]; 
extern int P_and_SP_macroblock_modes[32][7]; 
extern int B_Macroblock_Modes[50][7]; 

// the rest of it 

、右?

あなたのような何かをC/C++たびに

int myarray[4]; 
char mychar; 

以上の一般

type var_name; 

あなたはコンパイラに言っている:私のためにスタック上にXという名前の変数を割り当ててくださいをそのタイプはTです。

#include header.hの場合は、最も基本的な説明では、open header.h ctrl + c、ctrl + vここにプリプロセッサを伝えています。その前処理されたソースファイルはあなたのコンパイラに供給され、type var_nameと表示されるたびに上記で説明したことが実行されます。

申し訳ありませんが、これはあまりにも多くの情報ですが、私はちょうどそれを書くように感じた場合:あなたの答えのためのP

+0

申し訳ありませんが、明確にはしませんが、定義されているファイルはmacroblocktypes.hです。私はmacroblocktable.hがそれに宣言された変数を持っていることを知っています –

+0

私の編集を参照して、私は自分自身をより明確にしようとしました –

+0

@hexaまた、配列externを複数の定義を解決する...しかし、私は今の関数をどうすればいいのかわかりません! –

関連する問題