cmake multiple definition 问题解决方案

问题:C++ cmake编译 multiple definition of `constructTransformationMatrix(float const&, float const&, float const&, float const&, float const&, float const&)’

问题描述

我在调用xxx.h文件后,cmake编译出现:
CMakeFiles/PaintBot.dir/src/units/Camera.cpp.o: In function std::vector<pcl::PointXYZI, Eigen::aligned_allocator<pcl::PointXYZI> >::reserve(unsigned long)': /home/cecilma693/Documents/paintpot_mqh/include/units/registration.h:13: multiple definition ofconstructTransformationMatrix(float const&, float const&, float const&, float const&, float const&, float const&)’
CMakeFiles/PaintBot.dir/src/3dProc/Pcprocess.cpp.o:/home/cecilma693/Documents/paintpot_mqh/include/units/registration.h:13: first defined here
CMakeFiles/PaintBot.dir/src/units/Camera.cpp.o: In function refineAlignment(std::shared_ptr<pcl::PointCloud<pcl::PointXYZI> > const&, std::shared_ptr<pcl::PointCloud<pcl::PointXYZI> > const&, Eigen::Matrix<float, 4, 4, 0, 4, 4> const&, float, float, float, float)': /home/cecilma693/Documents/paintpot_mqh/include/units/registration.h:37: multiple definition ofrefineAlignment(std::shared_ptr<pcl::PointCloudpcl::PointXYZI > const&, std::shared_ptr<pcl::PointCloudpcl::PointXYZI > const&, Eigen::Matrix<float, 4, 4, 0, 4, 4> const&, float, float, float, float)’
CMakeFiles/PaintBot.dir/src/3dProc/Pcprocess.cpp.o:/home/cecilma693/Documents/paintpot_mqh/include/units/registration.h:37: first defined here
CMakeFiles/PaintBot.dir/src/3dProc/Geometry.cpp.o: In function BufferedReadWriteFile::BufferedReadWriteFile(char*, int)': /home/cecilma693/Documents/paintpot_mqh/src/3dProc/Geometry.cpp:14: warning: the use oftempnam’ is dangerous, better use `mkstemp’
collect2: error: ld returned 1 exit status
CMakeFiles/PaintBot.dir/build.make:1663: recipe for target ‘PaintBot’ failed
make[2]: *** [PaintBot] Error 1
CMakeFiles/Makefile2:67: recipe for target ‘CMakeFiles/PaintBot.dir/all’ failed
make[1]: *** [CMakeFiles/PaintBot.dir/all] Error 2
Makefile:83: recipe for target ‘all’ failed
make: *** [all] Error 2
经过一番寻找,再结合这上面描述的问题,发现是编译过程重复引用了不同的xxx.h文件,并且由于编译前后顺序的问题,这个报错的地方是.h文件的第二次编译,因此会出现重定义问题。

解决方法

按照提示,干掉Camera.cpp中的“#include<xxx.h>”,再次编译,通过!有问题请留言交流!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值