pcl_visualizer.h-致命错误LNK1120:1个未解决的外部零件 [英] pcl_visualizer.h - fatal error LNK1120: 1 unresolved externals
问题描述
error LNK2001: unresolved external symbol "public: virtual void __cdecl pcl::visualization::PCLVisualizer::FPSCallback::Execute(class vtkObject *,unsigned long,void *)" (?Execute@FPSCallback@PCLVisualizer@visualization@pcl@@UEAAXPEAVvtkObject@@KPEAX@Z)
1>C:\Users\hatea\Documents\Visual Studio 2015\Projects\PCLTester\x64\Debug\PCLTester.dll : fatal error LNK1120: 1 unresolved externals
我已经彻底用尽了解决此问题的所有途径.我在这里检查,发现了一个类似的问题/答案系列:包含以下内容时发生错误LNK2001 " pcl_visualizer.h"
I have thoroughly exhausted all avenues dealing with this issue. I checked here, and I found a similar question/answer series: error LNK2001 when including "pcl_visualizer.h"
问题是我不想注释掉FPSCallback方法.我正在使用的VTK可视化工具需要它.我确定当我在托管C ++/CLI库中引用.h文件时,只会收到未解决的外部错误.
The problem is that I do not want to comment out the FPSCallback method. I need it for the VTK visualizer I am using. I have determined that I only receive the unresolved external error when I reference the .h file in a managed C++/CLI library.
#pragma once
#pragma unmanaged
#include <pcl/visualization/pcl_visualizer.h>
#pragma managed
using namespace System;
namespace PCLTesterCLI
{
public ref class PCLTesterCLI
{
public:
PCLTesterCLI();
virtual ~PCLTesterCLI();
};
}
如果我在非托管Win32库中执行相同的操作,则库已成功构建.
If I do the same in an unmanaged Win32 library, the library is successfully built.
#pragma once
#include <pcl/visualization/pcl_visualizer.h>
class PCLTester
{
public:
PCLTester();
virtual ~PCLTester();
};
这是pcl_visualizer.h中的片段:
Here is the segment from pcl_visualizer.h:
struct FPSCallback : public vtkCommand
{
static FPSCallback *New () { return (new FPSCallback); }
FPSCallback () : actor (), pcl_visualizer (), decimated () {}
FPSCallback (const FPSCallback& src) : vtkCommand (), actor (src.actor), pcl_visualizer (src.pcl_visualizer), decimated (src.decimated) {}
FPSCallback& operator = (const FPSCallback& src) { actor = src.actor; pcl_visualizer = src.pcl_visualizer; decimated = src.decimated; return (*this); }
virtual void
Execute (vtkObject*, unsigned long event_id, void*);
vtkTextActor *actor;
PCLVisualizer* pcl_visualizer;
bool decimated;
};
/** \brief The FPSCallback object for the current visualizer. */
vtkSmartPointer<FPSCallback> update_fps_;
这是pcl_visualizer.cpp中的片段:
Here is the segment from pcl_visualizer.cpp:
void
pcl::visualization::PCLVisualizer::FPSCallback::Execute (
vtkObject* caller, unsigned long, void*)
{
vtkRenderer *ren = reinterpret_cast<vtkRenderer *> (caller);
float fps = 1.0f / static_cast<float> (ren->GetLastRenderTimeInSeconds ());
char buf[128];
sprintf (buf, "%.1f FPS", fps);
actor->SetInput (buf);
}
有什么想法为什么在托管环境中结构和成员函数会发生冲突?
Any ideas why the structure and member function conflict in a managed environment?
我的问题很独特的原因是我的符号错误不是我所做的任何事情的结果:在没有定义函数的情况下声明函数,语法错误导致函数未正确定义,或者从Linker-> Input忽略了.lib依赖项.就我而言,我链接了所有正确的.lib文件,而pcl :: visualization中的函数似乎定义良好.由于某些奇怪的原因,在托管库中仍会丢失它.我将依赖项从托管的.vcxproj复制到了非托管的.vcxproj,以验证它不是依赖性问题.两种类别均设置有最低类别要求,以防止这方面的冲突.这两个项目都有相同的.h文件和.lib文件链接.
The reason that my question is unique is that my symbols error was not a result of anything I did: e.g. declaring a function without defining it, having a syntax error that results in the function not being properly defined, or leaving out a .lib dependency from Linker->Input. In my case, I have all the correct .lib files linked and the function from pcl::visualization seems well defined. For some strange reason, it is still being missed at compile time in the managed library. I copied my dependencies from my managed .vcxproj to my unmanaged .vcxproj to verify that it was not a dependency issue. Both classes are setup with the minimum class requirements to prevent conflicts in that regard. Both projects have the same .h file and .lib files linked.
推荐答案
有趣的是,我将pcl_visualizer代码放在顶部的托管c ++代码中解决了此问题.我还必须添加标题:
Interestingly, I solved this issue by placing the pcl_visualizer code into my managed c++ code at the top. I had to add a header as well:
#include <vtkTextActor.h>
void
pcl::visualization::PCLVisualizer::FPSCallback::Execute(vtkObject* caller, unsigned long, void*)
{
vtkRenderer *ren = reinterpret_cast<vtkRenderer *> (caller);
float fps = 1.0f / static_cast<float> (ren->GetLastRenderTimeInSeconds());
char buf[128];
sprintf(buf, "%.1f FPS", fps);
actor->SetInput(buf);
}
另一种选择是进入pcl_visualizer.h并注释掉有问题的行(我不知道为什么这行会引起问题,但我将其缩小到这一范围,而我的vtk visualizer仍然有效!):
The other option is to go into pcl_visualizer.h and comment out the offending line (I do not know why this line causes issues, but I narrowed it down to this, and my vtk visualizer still works!):
//FPSCallback (const FPSCallback& src) : vtkCommand (), actor (src.actor), pcl_visualizer (src.pcl_visualizer), decimated (src.decimated) {}
代码如下:
struct FPSCallback : public vtkCommand
{
static FPSCallback *New () { return (new FPSCallback); }
FPSCallback () : actor (), pcl_visualizer (), decimated () {}
//FPSCallback (const FPSCallback& src) : vtkCommand (), actor (src.actor), pcl_visualizer (src.pcl_visualizer), decimated (src.decimated) {}
FPSCallback& operator = (const FPSCallback& src) { actor = src.actor; pcl_visualizer = src.pcl_visualizer; decimated = src.decimated; return (*this); }
virtual void
Execute (vtkObject*, unsigned long event_id, void*);
vtkTextActor *actor;
PCLVisualizer* pcl_visualizer;
bool decimated;
};
/** \brief The FPSCallback object for the current visualizer. */
vtkSmartPointer<FPSCallback> update_fps_;
这篇关于pcl_visualizer.h-致命错误LNK1120:1个未解决的外部零件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!