renlianjiance.o(.data+0x0): first defined here
main.o(.data+0x880): multiple definition of `LBP_tree'
renlianjiance.o(.data+0x880): first defined here
main.o(.data+0x2080): multiple definition of `LBP'
renlianjiance.o(.data+0x2080): first defined here
main.o(.data+0x2120): multiple definition of `std_g_jh'
renlianjiance.o(.data+0x2120): first defined here
collect2: ld returned 1 exit status
make: *** [renlianjiance] Error 1
这是我做人脸检测时候的一个错误。该错误的原因是在头文件中定义了数组或者数据结构并且初始化。
#ifndef STRUCT_TREE
#define STRUCT_TREE
struct tree
{
int rect_number;
signed int feature[8];
float leafvalue[2];
}struct tree LBP_tree[139]={};//没有将定义和初始化分来
#endif
尽管使用了#ifndef #define *****#endif 语句来避免重复包含,这在编译的时候可以通过,但是在链接的时候就会产生上述错误。初始化后分配了空间,会使得所有引用了相同头文件的文件都包含了初始化的数据。
以下是我的更改:
#ifndef STRUCT_TREE
#define STRUCT_TREE
struct tree
{
int rect_number;
signed int feature[8];
float leafvalue[2];
};
#endif
struct tree LBP_tree[139]={};//将定义和初始化分来
然后再使用到struct tree的文件里面使用
#ifndef STRUCT_TREE
#define STRUCT_TREE
struct tree
{
int rect_number;
signed int feature[8];
float leafvalue[2];
};
#endif
这样就可以了,避免了重复定义,重复分配空间。其他的错误一次解决。