【问题标题】:Linking error when including <pcl/io/png_io.h> in more than one file在多个文件中包含 <pcl/io/png_io.h> 时出现链接错误
【发布时间】:2014-02-12 12:29:50
【问题描述】:

我想在我的代码中的两个源文件中使用pcl::io::savePNGFile

只要我在第二个源文件中包含所需的包含

# include <pcl/io/png_io.h>

项目无法编译。

错误信息是:

/usr/include/pcl-1.7/pcl/io/png_io.h:86: multiple definition of `pcl::io::saveRgbPNGFile(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned char const*, int, int)'

我将把函数包装在一个类中,以便在项目中只包含一次。但我认为这不是最好的方法。我做错了什么吗?有更好的解决方案吗?

谢谢!

编辑

最后我实现了一个问答解决方案并封装了函数(仅适用于普通云)

cloudsaver.h

#ifndef CLOUDSAVER_H
#define CLOUDSAVER_H        

#include <pcl/point_types.h>
#include <pcl/point_cloud.h>
#include <string>

class CloudSaver
{

public:
    CloudSaver();

    void saveCloudToPNG(const std::string & fileName, const pcl::PointCloud<pcl::PointXYZRGBNormal>& cl );
};

#endif // CLOUDSAVER_H

cloudsaver.cpp

#include "cloudsaver.h"

# include <pcl/io/png_io.h>

CloudSaver::CloudSaver()
{

}

void CloudSaver::saveCloudToPNG(const std::string & fileName, const pcl::PointCloud<pcl::PointXYZRGBNormal>& cl )
{
    pcl::io::savePNGFile<pcl::PointXYZRGBNormal>(fileName, cl );
}

但我还是很好奇,如何正确地做到这一点。

【问题讨论】:

    标签: point-cloud-library


    【解决方案1】:

    据我所知,存在一些与 png_io.h 相关的问题。

    我已经用这个定义更改了png_io.h文件中PCL_DEPRECATED的定义,一切都变得OK了。

    template <typename T>
    PCL_DEPRECATED (void savePNGFile (const std::string& file_name, const pcl::PointCloud<T>&     cloud),
    "pcl::io::savePNGFile<typename T> (file_name, cloud) is deprecated, please use a new generic "
    "function pcl::io::savePNGFile (file_name, cloud, field_name) with \"rgb\" as the field name."
    );
    

    查看此链接 [https://github.com/PointCloudLibrary/pcl/pull/300]

    【讨论】:

    【解决方案2】:

    我猜你正在使用 PCL 的静态版本。

    要解决此问题,您需要将这些方法声明为内联

    例如,对于 PCL 1.7.1,您需要编辑此文件: pcl-pcl-1.7.1/io/include/pcl/io/png_io.h

    在这些行上,添加关键字 inline:

    85: inline saveRgbPNGFile(...
    96: inline savePNGFile(...
    107: inline savePNGFile(...
    119: inline savePNGFile(...
    173: inline savePNGFile(...
    

    现在重新构建库,您应该能够毫无问题地进行编译。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-07
      • 1970-01-01
      • 2020-03-11
      • 2018-09-07
      • 2019-12-02
      • 1970-01-01
      • 2016-05-08
      相关资源
      最近更新 更多