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
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"
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();
};
}
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();
};
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_;
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?
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.
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:
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!):
The code then looks like: