尽管我在所有头文件中都包含了头文件,但是当我创建头文件PointXYZRGBAI.h并将其包含在LidarFile.cpp和core.cpp,生成多个文件使用的头文件中的结构声明导致架构x86_64的重复符号
duplicate symbol _EIGEN_ALIGN_16 in:
CMakeFiles/core.dir/core.cpp.o
CMakeFiles/core.dir/LidarFile.cpp.o
ld: 1 duplicate symbol for architecture x86_64
错误和误差似乎标题中抱怨是
#define PCL_NO_PRECOMPILE
#ifndef POINTXYZRGBAI_H
#define POINTXYZRGBAI_H
#endif
#include <pcl/point_types.h>
struct PointXYZRGBAI{
PCL_ADD_POINT4D;
union{
struct{
float intensity;
uint32_t rgba;
};
float data_c[4];
};
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
} EIGEN_ALIGN_16;
POINT_CLOUD_REGISTER_POINT_STRUCT(PointXYZRGBAI,
(float, x, x)
(float, y, y)
(float, z, z)
(float, intensity, intensity)
(uint32_t, rgba, rgba)
)
inline std::ostream& operator << (std::ostream& os, const PointXYZRGBAI& p){
os << "(" << p.x << ", " << p.y << ", " << p.z << " - " << p.intensity << " - " << p.rgba << ")";
return (os);
}
和我用EIGEN_ALIGN_16在我的标头中定义结构为内存对齐。为什么EIGEN_ALIGN_16是一个重复的符号,如果一个头卫兵应该防止多重包含?谢谢你的澄清。
除了很好的答案,你的'endif'应该在头文件的末尾,否则它是无用的。 – Phil1970
“标题”文件通常只有声明(类型和名称,也称为接口)。这些定义(所有的实现细节)通常进入实现文件,后缀为.c或.cpp。 –