Pergunta

I wanted to use pcl::io::savePNGFile in two source-files in my code.

As soon as I include the required include in second source-file

# include <pcl/io/png_io.h>

the project doesn't compile.

The error message is:

/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)'

I'm going to wrap the function in a class in order to include it only once in project. But I think it is not the best way. Am I doing something in a wrong way? Is there a better solution?

Thanks!

EDIT

Finally I've implemented a Q&D solution and wrapped the function (only for normal clouds)

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 );
}

But I'm still curious, how to do it properly.

Foi útil?

Solução

As far as I know, There are some issues related to png_io.h.

I have change the definition of PCL_DEPRECATED in png_io.h file with this definition,and every thing becomes 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."
);

look at this link [https://github.com/PointCloudLibrary/pcl/pull/300]

Outras dicas

I guess you are using the static version of PCL.

To solve this issue you need to declare those methods as inline.

For example, for PCL 1.7.1, you need to edit this file: pcl-pcl-1.7.1/io/include/pcl/io/png_io.h

And on these lines, add the keyword inline:

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

Now rebuild the library, and you should be able to compile without any issues.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top