複数のファイルでポイントクラウドライブラリとOpenCVを使用してテストプロジェクトを実装しようとしています。コンパイルしようとすると、「定義済みエラー」メッセージが表示されます。おそらく私は何らかの理由で実現できない愚かなことをしています-私はここで見つけたいくつかの解決策を試しましたが、私の場合はどれも役に立たなかったようです。
私が持っているもの:
libs.hファイル。libファイルをロードします(プロジェクトのプロパティでは、.libパスを設定し、ヘッダーのように「手動で」libsをロードするだけです)。
#pragma once
#ifndef PCLTEST_LIBS
#define PCLTEST_LIBS
#ifdef _DEBUG
#pragma comment(lib, "pcl_apps-gd.lib")
#pragma comment(lib, "pcl_common-gd.lib")
// a bunch of other debug libs
#else
// the release libs
#endif
#endif
デバッグするために、この時点で基本的にすべてを削除したメインファイル:
// load the libs
#ifndef PCLTEST_LIBS
#include "libs.h"
#endif
// pcltest includes
// if only this first one is #included, everything is OK
#include "opencvOperations.h"
// #including this one causes the error
#include "files.h"
// these ones are not working also
//#include "cloudOperations.h"
//#include "visualize.h"
// c++ headers
#include <stdio.h>
#include <string>
//#include <sstream>
//#include <iostream>
void writeInfo()
{
// some std::cout calls
}
int main( int argc, char* argv[] )
{
writeInfo();
// this function is in opencvOperations.h and works OK
pcltest::openLena();
}
次に、main.objにいくつかの(PCL関連の)シンボルがfiles.objですでに定義されているというエラーメッセージが表示されます。opencvOperationsとファイルの両方でPCL関連の呼び出しを使用しています。最初の呼び出しは問題なく、2番目の呼び出しは機能しません。
編集: 詳細を追加するには、私のfiles.hヘッダー:
#pragma once
#ifndef PCLTEST_FILES
#define PCLTEST_FILES
// pcl headers
#ifndef PCL_COMMON_H_
#include <pcl/common/common_headers.h>
#endif
#ifndef PCL_IO_FILE_IO_H_
#include <pcl/io/file_io.h>
#endif
#ifndef PCL_IO_PCD_IO_H_
#include <pcl/io/pcd_io.h>
#endif
#ifndef PCL_IO_PLY_IO_H_
#include <pcl/io/ply_io.h>
#endif
// boost headers
#ifndef BOOST_FILESYSTEM_OPERATIONSX_HPP
#include <boost/filesystem/operations.hpp>
#endif
#endif
namespace pcltest
{
// function to open PCL or binary PLY files
pcl::PointCloud<pcl::PointXYZ>::Ptr openCloud(std::string filename);
// function to save the point cloud to PCD format
void saveCloud();
}
コードを別々のファイルに分割する前は、すべてがうまく機能していました(同じプロジェクト設定で)。
Edit2:
問題の原因を突き止めました。
#include <pcl/io/ply_io.h>
これを引き起こします。今のところ、PLYに関連するすべてのものを取り除き、すべてが正常に機能します。後で見ていきますが、これはPCLライブラリ固有の問題である可能性があります。この呼び出しによって、PLY関連の関数/変数を使用していない他のファイルでリンカーエラーが発生する理由は、私にはまだ不思議です。