怎么解决"multiple definition of"错误

liubo1977 liubo1977 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我有三个文件:
文件件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
请问这是怎么回事????
...全文

相关推荐

评论 5
收藏 已收藏
分享
返回顶部
liubo1977
C语言 70,039 成员 243,237 内容