我正在尝试使用PCL编译一个简单的程序,链接器可以正确链接该指令:
pcl::SHOTEstimationOMP<pcl::PointXYZRGBA, pcl::Normal, pcl::SHOT352> shot_descriptor;
但是这一个:
pcl::SHOTColorEstimationOMP<pcl::PointXYZRGBA, pcl::Normal, pcl::SHOT352> shot_descriptor;
我收到:
Linking CXX executable ../../../bin/gcc5_2/RGBDNN_PCL_Descriptord
CMakeFiles/RGBDNN_PCL_Descriptor.dir/__/__/src/pcl_descriptor.cpp.o:(.rodata._ZTVN3pcl22SHOTColorEstimationOMPINS_12PointXYZRGBAENS_6NormalENS_7SHOT352ENS_14ReferenceFrameEEE[_ZTVN3pcl22SHOTColorEstimationOMPINS_12PointXYZRGBAENS_6NormalENS_7SHOT352ENS_14ReferenceFrameEEE]+0x48): undefined reference to `pcl::SHOTColorEstimationOMP<pcl::PointXYZRGBA, pcl::Normal, pcl::SHOT352, pcl::ReferenceFrame>::initCompute()'
CMakeFiles/RGBDNN_PCL_Descriptor.dir/__/__/src/pcl_descriptor.cpp.o:(.rodata._ZTVN3pcl22SHOTColorEstimationOMPINS_12PointXYZRGBAENS_6NormalENS_7SHOT352ENS_14ReferenceFrameEEE[_ZTVN3pcl22SHOTColorEstimationOMPINS_12PointXYZRGBAENS_6NormalENS_7SHOT352ENS_14ReferenceFrameEEE]+0x58): undefined reference to `pcl::SHOTColorEstimationOMP<pcl::PointXYZRGBA, pcl::Normal, pcl::SHOT352, pcl::ReferenceFrame>::computeFeature(pcl::PointCloud<pcl::SHOT352>&)'
CMakeFiles/RGBDNN_PCL_Descriptor.dir/__/__/src/pcl_descriptor.cpp.o:(.rodata._ZTVN3pcl22SHOTColorEstimationOMPINS_12PointXYZRGBAENS_6NormalENS_7SHOT352ENS_14ReferenceFrameEEE[_ZTVN3pcl22SHOTColorEstimationOMPINS_12PointXYZRGBAENS_6NormalENS_7SHOT352ENS_14ReferenceFrameEEE]+0x60): undefined reference to `pcl::SHOTColorEstimation<pcl::PointXYZRGBA, pcl::Normal, pcl::SHOT352, pcl::ReferenceFrame>::computePointSHOT(int, std::vector<int, std::allocator<int> > const&, std::vector<float, std::allocator<float> > const&, Eigen::Matrix<float, -1, 1, 0, -1, 1>&)'
CMakeFiles/RGBDNN_PCL_Descriptor.dir/__/__/src/pcl_descriptor.cpp.o:(.rodata._ZTVN3pcl19SHOTColorEstimationINS_12PointXYZRGBAENS_6NormalENS_7SHOT352ENS_14ReferenceFrameEEE[_ZTVN3pcl19SHOTColorEstimationINS_12PointXYZRGBAENS_6NormalENS_7SHOT352ENS_14ReferenceFrameEEE]+0x58): undefined reference to `pcl::SHOTColorEstimation<pcl::PointXYZRGBA, pcl::Normal, pcl::SHOT352, pcl::ReferenceFrame>::computeFeature(pcl::PointCloud<pcl::SHOT352>&)'
CMakeFiles/RGBDNN_PCL_Descriptor.dir/__/__/src/pcl_descriptor.cpp.o:(.rodata._ZTVN3pcl19SHOTColorEstimationINS_12PointXYZRGBAENS_6NormalENS_7SHOT352ENS_14ReferenceFrameEEE[_ZTVN3pcl19SHOTColorEstimationINS_12PointXYZRGBAENS_6NormalENS_7SHOT352ENS_14ReferenceFrameEEE]+0x60): undefined reference to `pcl::SHOTColorEstimation<pcl::PointXYZRGBA, pcl::Normal, pcl::SHOT352, pcl::ReferenceFrame>::computePointSHOT(int, std::vector<int, std::allocator<int> > const&, std::vector<float, std::allocator<float> > const&, Eigen::Matrix<float, -1, 1, 0, -1, 1>&)'
collect2: error: ld returned 1 exit status
cmake/pcl_descriptor/CMakeFiles/RGBDNN_PCL_Descriptor.dir/build.make:193: recipe for target '../bin/gcc5_2/RGBDNN_PCL_Descriptord' failed
make[2]: *** [../bin/gcc5_2/RGBDNN_PCL_Descriptord] Error 1
CMakeFiles/Makefile2:175: recipe for target 'cmake/pcl_descriptor/CMakeFiles/RGBDNN_PCL_Descriptor.dir/all' failed
make[1]: *** [cmake/pcl_descriptor/CMakeFiles/RGBDNN_PCL_Descriptor.dir/all] Error 2
Makefile:75: recipe for target 'all' failed
make: *** [all] Error 2
*** Failure: Exit code 2 ***
这两个类位于相同的头文件和源文件中:
我自己编译了这些库。
有什么问题?
ANSWER
由于问题关闭得太快,我没有时间解释为什么它不是重复的。错误是由于两个类的默认参数而不是链接库。
这些类在标题中以这种方式声明:
template <typename PointInT, typename PointNT, typename PointOutT = pcl::SHOT352, typename PointRFT = pcl::ReferenceFrame>
class SHOTEstimationOMP : public SHOTEstimation<PointInT, PointNT, PointOutT, PointRFT>
template <typename PointInT, typename PointNT, typename PointOutT = pcl::SHOT1344, typename PointRFT = pcl::ReferenceFrame>
class SHOTColorEstimationOMP : public SHOTColorEstimation<PointInT, PointNT, PointOutT, PointRFT>
你不能声明PointOutT等于SHOT352的SHOTColorEstrimationOMP,因为它已经在声明中有一个指定的类型。