pcl_visualizer.h - fatal error LNK1120: 1 unresolved externals

爱⌒轻易说出口 提交于 2019-12-25 04:26:31

问题


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.


回答1:


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);
}

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) {}

The code then looks like:

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_;


来源:https://stackoverflow.com/questions/41194069/pcl-visualizer-h-fatal-error-lnk1120-1-unresolved-externals

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!