我正在尝试使用带有多个文件的点云库和 OpenCV 来实现一个测试项目。当我尝试编译时,我收到“已定义错误”消息。可能我正在做一些由于某种原因无法实现的愚蠢行为 - 我尝试了一些在这里找到的解决方案,但它们似乎都对我没有帮助。
我有的:
一个 libs.h 文件,我在其中加载 lib 文件(在项目属性中,我只设置 .lib 路径并“手动”加载 lib,如标题):
#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 中收到几条错误消息,表明 files.obj 中已经定义了一些(PCL 相关的)符号。我在 opencvOperations 和 files 中都使用 PCL 相关调用,第一个可以,第二个不起作用。
编辑: 要添加更多详细信息,我的 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();
}
在将代码拆分为单独的文件之前,一切正常(使用相同的项目设置)。
编辑2:
我找到了问题的根源,
#include <pcl/io/ply_io.h>
导致这个。现在,我摆脱了与 PLY 相关的所有内容,一切正常。我稍后再看,这可能是 PCL 库特定的问题。我仍然很奇怪为什么这个调用会导致另一个文件中的链接器错误,我什至不使用 PLY 相关的函数/变量。