【转】PCL+VS报错:error C4996: 'pcl::SAC_SAMPLE_SIZE': PCL1.8问题汇总

转载自:https://blog.csdn.net/wokaowokaowokao12345/article/details/51287011

引言

在使用PCL1.8.0时可能出现各类编译错误信息,这篇博文就是将遇到的这些问题及解决方法进行汇总。

头文件中包含了:#include <pcl/sample_consensus/model_types.h> 就会出现问题

错误与解决方法

错误信息

今天使用PCL1.8编译官方教程中ICP例子时,出现下列错误:

error C4996: 'pcl::SAC_SAMPLE_SIZE': This map is deprecated and is kept only to prevent breaking existing user code. Starting from PCL 1.8.0 model sample size is a protected member of the SampleConsensusModel class

解决方法

感谢pcl学习群的codeman。 
打开项目属性页>C/C++>常规>SDL检查(设置为否)。 


这里写图片描述
重新编译,原先的错误信息变成了警告。

若上面的方法无法解决这个错误,可以打开头文件”model_types.h”,修改其中的代码: 
源码:

namespace pcl
{
  const static std::map<pcl::SacModel, unsigned int>
      PCL_DEPRECATED("This map is deprecated and is kept only to prevent breaking "
      "existing user code. Starting from PCL 1.8.0 model sample size "
      "is a protected member of the SampleConsensusModel class")
  SAC_SAMPLE_SIZE (sample_size_pairs, sample_size_pairs + sizeof (sample_size_pairs) / sizeof (SampleSizeModel));
}

修改后:

namespace pcl
{
  const static std::map<pcl::SacModel, unsigned int>
      //PCL_DEPRECATED("This map is deprecated and is kept only to prevent breaking "
      //"existing user code. Starting from PCL 1.8.0 model sample size "
      //"is a protected member of the SampleConsensusModel class")
  SAC_SAMPLE_SIZE (sample_size_pairs, sample_size_pairs + sizeof (sample_size_pairs) / sizeof (SampleSizeModel));
}

重新编译即可解决问题。

错误信息

d:\clibrary\pcl1.8.0\pcl1.8.0x86\3rdparty\flann\include\flann\util\serialization.h(362): error C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

解决方法

打开项目属性页>C/C++>预处理器,添加:

_CRT_SECURE_NO_WARNINGS

错误信息

conditional_euclidean_clustering.obj : error LNK2001: 无法解析的外部符号 "public: void __cdecl pcl::ConditionalEuclideanClustering<struct pcl::PointXYZINormal>::segment(class std::vector<struct pcl::PointIndices,class std::allocator<struct pcl::PointIndices> > &)" (?segment@?$ConditionalEuclideanClustering@UPointXYZINormal@pcl@@@pcl@@QEAAXAEAV?$vector@UPointIndices@pcl@@V?$allocator@UPointIndices@pcl@@@std@@@std@@@Z)
1>conditional_euclidean_clustering.obj : error LNK2001: 无法解析的外部符号 "protected: virtual void __cdecl pcl::NormalEstimation<struct pcl::PointXYZI,struct pcl::PointXYZINormal>::computeFeature(class pcl::PointCloud<struct pcl::PointXYZINormal> &)" (?computeFeature@?$NormalEstimation@UPointXYZI@pcl@@UPointXYZINormal@2@@pcl@@MEAAXAEAV?$PointCloud@UPointXYZINormal@pcl@@@2@@Z)
1>E:\VisualStudio2013Project\PCLConsoleApplication\x64\Release\ConditionalEuclideanClustering.exe : fatal error LNK1120: 2 个无法解析的外部命令

在所有库都配置的情况下,若出现上述问题。

解决方法

打开项目属性页>C/C++>预处理器,添加:

PCL_NO_PRECOMPILE

错误信息

F:\PCL1.8.0\3rdParty\FLANN\include\flann/util/serialization.h(362): error C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>          F:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\stdio.h(211) : 参见“fopen”的声明

解决方法

打开项目属性页>C/C++>预处理器,添加:

_CRT_SECURE_NO_WARNINGS

错误信息

e:\shizhenwei\vs2013projects\testicp1\testicp1\main.cpp(39): error C4996: 'pcl::Registration<PointSource,PointTarget,Scalar>::setInputCloud': [pcl::registration::Registration::setInputCloud] setInputCloud is deprecated. Please use setInputSource instead.
1>          with
1>          [
1>              PointSource=pcl::PointXYZ
1>  ,            PointTarget=pcl::PointXYZ
1>  ,            Scalar=float
1>          ]
1>          d:\clibrary\pcl1.8.0\pcl1.8.0x86\include\pcl-1.8\pcl\registration\registration.h(183) : 参见“pcl::Registration<PointSource,PointTarget,Scalar>::setInputCloud”的声明
1>          with
1>          [
1>              PointSource=pcl::PointXYZ
1>  ,            PointTarget=pcl::PointXYZ
1>  ,            Scalar=float
1>          ]

解决方法

    //icp.setInputCloud(cloud_in);
    icp.setInputSource(cloud_in);

总结

在VS中编译开源库的工程,产生的问题可能五花八门,但其问题提示是比较清楚的,根据提示解决可以以不变应万变。实在解决不了,也可以问问度娘或google,正所谓内事不决问百度,外事不决问google。

猜你喜欢

转载自blog.csdn.net/liukunrs/article/details/80361134
今日推荐