2

複数のファイルでポイントクラウドライブラリと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関連の関数/変数を使用していない他のファイルでリンカーエラーが発生する理由は、私にはまだ不思議です。

4

2 に答える 2

8

私はあなたと同じ問題を抱えていました。私はsurface.hとsurface.cppファイルを持っていましたが、surface.hではなくsurface.cppからply_io.hファイルを含める必要があることがわかりました。これで正常にコンパイルされます。それがお役に立てば幸いです。はは

于 2012-01-13T23:12:07.623 に答える
2

インクルードで定数がインスタンス化されている場合は、http://msdn.microsoft.com/en-us/library/5tkz6s71%28v=vs.80%29.aspxに従ってselectanyを使用することもできます-私の場合:

const int CSdata[] = {1, 2, 3, 4};

複数のソースパーツに含まれている場合、リンク時にLNK2005が生成され、次の方法で回避されます。

const __declspec(selectany) int CSdata[] = {1, 2, 3, 4};

ポータブルではない、ええ..。

于 2012-09-11T15:31:42.457 に答える