怎么解决"multiple definition of"错误
我有三个文件:
文件件1,名为test.c:
#include<stdio.h>
#include"mytest.h"
int main()
{
ct_new_0[1][2]=9;
ct_new_1[2][2]=10;
}
文件2,名为:test1.c
#include"mytest.h"
void f()
{
greyTable[1][1]=12;
}
文件3,是头文件,名为:mytest.h:
#ifndef _MYTEST_H_
#define _MYTEST_H_
short ct_new_0[1024][3]=
{
{255, 255, 255} //B??
};
unsigned char ct_new_1[1024][3]=
{
//????1
{0,0,255}
};
unsigned char ct_new_2[1024][3]=
{
{255,255,255}
};
unsigned char greyTable[256][3]=
{
{252, 252, 252}
};
#endif
在gcc下面编译如下:
gcc -o test test1.c test.c
报错为:
/tmp/ccHm7uiD.o(.data+0x0): multiple definition of `ct_new_0'
/tmp/ccwMLEMM.o(.data+0x0): first defined here
/tmp/ccHm7uiD.o(.data+0x1800): multiple definition of `ct_new_1'
/tmp/ccwMLEMM.o(.data+0x1800): first defined here
/tmp/ccHm7uiD.o(.data+0x2400): multiple definition of `ct_new_2'
/tmp/ccwMLEMM.o(.data+0x2400): first defined here
/tmp/ccHm7uiD.o(.data+0x3000): multiple definition of `greyTable'
/tmp/ccwMLEMM.o(.data+0x3000): first defined here
请问这是怎么回事????