怎么解决"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
请问这是怎么回事????
文件件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
请问这是怎么回事????
...全文
相关推荐
文件编译时出现multiple definition of 'xxxxxx'的具体解决方法
"解决文件编译时出现'multiple definition of'错误的方法"在编程过程中,当编译器报告“multiple definition of 'xxxxxx'”的错误时,这意味着你在不
文件编译时出现multiple definition of ‘xxxxxx’的具体解决方法
在进行Linux系统下的C语言编程时,可能会遇到编译错误“multiple definition of ‘xxxxxx’”。这个问题通常发生在多个源文件中包含了相同的函数或全局变量定义,导致链接时冲突
ARM常见的编译错误
**重定义符号(Multiple Definitions)** - **错误示例**:“multiple definition of `variable_name`” - **原因**:同一符号在多个位置被定义
Delphi编译错误中文手册
- 解决方法:确保局部变量在使用前已正确初始化。22. **Cannot initialize multiple variables** - 错误描述:无法同时初始化多个变量。
头文件不宜定义变量的原因全面解析
如果多个源文件包含相同的头文件并定义了相同的全局变量,编译器在链接阶段会发现这些重复的定义,导致“multiple definition of”错误。


