pcl_visualizer.h - fatal error LNK1120: 1 unresolved externals - point-cloud-library

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

Related

QT static library how to export template

I have a helper class that needs a template definition and works fine locally.
Now I try to put it in a static libary and use it in another program.
But when I use it, the linker reports a non-existent symbol. Is it possible to export the template definition somehow?
core_global.h
#pragma once
#include <QtCore/qglobal.h>
#define CORE_EXPORT Q_DECL_EXPORT
helper.h
#pragma once
#include "core_global.h"
template <typename E>
class CORE_EXPORT Helper
{
public:
Helper();
E fromString(const QString& text);
QString toString(E value);
};
helper.cpp
#include "Helper.h"
template<typename E>
Helper<E>::Helper()
{
}
template<typename E>
E Helper<E>::fromString(const QString& text)
{
// do something
return {};
}
template<typename E>
QString Helper<E>::toString(E value)
{
//do something
return {};
}

Error: C2280 Creating a vector of unique_ptr to Class

It seems that when using a unique_ptr in vector<unique_ptr<UserInterface>> I get an error stating:
Error 1 error C2280: 'std::unique_ptr<UserInterface,std::default_delete<_Ty>>::unique_ptr(const std::unique_ptr<_Ty,std::default_delete<_Ty>> &)' : attempting to reference a deleted function c:\pr...ude\xmemory0 593 1 Win32Project1
Seemingly, no configuration allows me to store [smart] pointers to the UserInterface class, which has a simple structure:
#define InterfaceContruct vector<unique_ptr<UserInterface>>
class UserInterfaceMgmt
{
public:
UserInterfaceMgmt();
~UserInterfaceMgmt();
InterfaceContruct Interface;
void AddUIElement();
void RemoveUIElement();
void DrawInterface();
void MoveElement();
private:
};
Even if no function is called, the error shows up (InterfaceContruct Interface; is instantiated) I tried putting the copy constructor in private but it persists.
The .cpp file is:
#include "stdafx.h"
#include "UserInterfaceMgmt.h"
UserInterfaceMgmt::UserInterfaceMgmt()
{
}
UserInterfaceMgmt::~UserInterfaceMgmt()
{
}
void UserInterfaceMgmt::DrawInterface(){
for (UINT i = 0; i < Interface.size(); i++)
{
Interface[i]->Draw();
}
}
std::vector (and most other containers in std::) require the value type to be copy-constructible. std::unique_ptr isn't copy constructible. Use std::shared_ptr or any other copy constructible types / pointers.
The clue is to look for attempting to reference a deleted function. This means there is some method which = delete has been used with. For instance:
struct Foo
{
Foo(const Foo & rhs) = delete; // A deleted function
}

Qt tr() translation with static members and namespaces

I'm working on translation our Qt GUI project.
*.ts file is generated successfully.
I filled *.ts file with translations using Qt Linguist.
But at runtime, translation with namespaces and static members does not work.
Other translations (when tr() method calls in class, that are inherited from QObject) works ok.
I have the following code (translation does not work):
Example with namespaces:
// example with namespaces
// declaration in header
namespace Error
{
namespace RadionetworkInput
{
QString alreadyInUse = QT_TR_NOOP("already in use");
char requestFailed[] = QT_TR_NOOP("request failed");
}
}
Usage in cpp:
// usage in cpp code0
QString error0 = Error::RadionetworkInput::alreadyInUse;
QString error1 = tr(Error::RadionetworkInput::requestFailed);
Example with static members:
// example with static members
// declaration in header
namespace Error
{
class RadionetworkInput
{
public:
static const QString alreadyInUse;
static const char requestFailed[];
}
QString Error::RadionetworkInput::alreadyInUse = QT_TR_NOOP("already in use");
char Error::RadionetworkInput::requestFailed[] = QT_TR_NOOP("request failed");
}
Usage in cpp code
// usage in cpp code
QString error0 = Error::RadionetworkInput::alreadyInUse;
QString error1 = tr(Error::RadionetworkInput::requestFailed);
Example, with working translation:
class ViewNetwork : public QObject
{
Q_OBJECT
public:
explicit ViewNetwork(QString name = tr("New Radionetwork"));
};
Usage in code:
ViewNetwork::ViewNetwork(QString name)
{
QString dummy = name;
}
Using QObject::tr() instead QT_TR_NOOP() macro does not help.
Problem is your understanding how it works. With static members variables they are initialized before main function starts.
This means two thing:
they are initialized before QApplication object is created and before yuo load translation files! (I'm surprised that this didn't lead to a crash)
value is calculated only once (not updated if translation changes)!
What you should do? Just change static variable to functions:
// example with namespaces
// declaration in header
namespace Error
{
namespace RadionetworkInput
{
QString alreadyInUse() { return QT_TR_NOOP("already in use"); }
QString requestFailed() { return QT_TR_NOOP("request failed"); }
}
}
and
// example with static members
// declaration in header
namespace Error
{
class RadionetworkInput
{
public:
static QString alreadyInUse();
static QString requestFailed();
}
QString Error::RadionetworkInput::alreadyInUse() { return QT_TR_NOOP("already in use"); }
QString Error::RadionetworkInput::requestFailed() { return QT_TR_NOOP("request failed"); }
}
Returning translation as char[] is pointless, co I've corrected that also (I don't know why you did it).

Syntax error: missing ';' before '*' when creating a pointer object of a user defined abstract class

I am trying to create pointer objects for my defined class 'FeralScene'
But i keep getting this error "Syntax error: missing ';' before '*'"
i dont know wats wrong with my code... could smone pls help me out?
/***********************************************************************
2D Engine Header File
File Name: FeralFramework
File Desc: Header to the Main Framework file
************************************************************************/
#ifndef FERALFRAMEWORK_H
#define FERALFRAMEWORK_H
#pragma once
#include<Windows.h>
#include<d3d9.h>
#include<d3dx9.h>
#include<string>
#include <dinput.h>
#include"FeralScene.h"
#include"GraphicDevice.h"
#include "Stdinc.h"
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
class FeralFramework
{
public:
LPDIRECTINPUT8 inputDevice;
LPDIRECT3DDEVICE9 Device;
HWND WindowHandler;
HINSTANCE Instance;
FeralScene *CurrentScene,*PrevScene; // error occurs here
GraphicDevice graphicDevice;
static HWND StaticWindowHandle;
static IDirect3DDevice9 *GraphDevice;
int ScreenHeight;
int ScreenWidth;
bool IsFullScreen;
bool WindowCreation();
bool InitDirectx();
void MessageLoop();
void SetLighting();
void UpdateDrawLoopCallFunction();
void InitFrameWork();
void Render();
void initializeDirectInput();
//void Camera(int mx, int my);
void SceneSwitcher(FeralScene *SCENETOSWITCHTO);
// the FeralScene identifier error occurs here
FeralFramework();
FeralFramework(HINSTANCE Instance,int ScreenHeight,int ScreenWidth ,bool IsFullScreen,FeralScene *SentSceneObject );
// the FeralScene identifier error occurs here
FeralFramework(HINSTANCE Instance,FeralScene *SentSceneObject);
// the FeralScene identifier error occurs here
};
inline LRESULT CALLBACK WndProc(HWND WindowHandler,UINT Msg,WPARAM wparam,LPARAM lparam)
{
switch(Msg)
{
case WM_DESTROY:
PostQuitMessage(0);
return true;
default:
return DefWindowProc(WindowHandler,Msg,wparam,lparam);
}
}
#endif
And here is a list of the errors that pop up when i try to compile it
1>c:\users\sys\documents\visual studio 2010\projects\feralengine\feralengine\feralframework.h(33): error C2143: syntax error : missing ';' before '*'
1>c:\users\sys\documents\visual studio 2010\projects\feralengine\feralengine\feralframework.h(33): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\sys\documents\visual studio 2010\projects\feralengine\feralengine\feralframework.h(33): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\sys\documents\visual studio 2010\projects\feralengine\feralengine\feralframework.h(33): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\sys\documents\visual studio 2010\projects\feralengine\feralengine\feralframework.h(55): error C2061: syntax error : identifier 'FeralScene'
1>c:\users\sys\documents\visual studio 2010\projects\feralengine\feralengine\feralframework.h(58): error C2061: syntax error : identifier 'FeralScene'
1>c:\users\sys\documents\visual studio 2010\projects\feralengine\feralengine\feralframework.h(59): error C2061: syntax error : identifier 'FeralScene'
What am i missing ? Any help will be appreciated :(
And here is the code for FeralScene
/***********************************************************************
2D Engine Header File
File Name: FeralScene
File Desc: Header to the FeralScene file
************************************************************************/
#pragma once
#include<d3dx9.h>
#pragma once
#include<Windows.h>
#include<d3d9.h>
#include<d3dx9.h>
#include"GraphicDevice.h"
#include "FeralFramework.h"
//#include "Vector.h"
class FeralScene
{
public:
HWND WindowHandler;
IDirect3DDevice9 *Device;
int BackBufferHeight;
int BackBufferWidth;
bool IsFullScreen,HasLoadedResources,HasUnloadedResources;
virtual void Initialize(FeralScene *SentSceneObject) =0;
virtual void Load(GraphicDevice graphicDevice) =0;
virtual void Update(GraphicDevice graphicDevice) =0;
virtual void Draw(GraphicDevice graphicDevice) =0;
virtual void Unload() =0;
virtual void Lighting()=0;
virtual void LoadAnim()=0;
virtual void UnloadAnim()=0;
};
You are including FeralFrameWork.h in feralscene.h. Which doesnt know of FeralScene.h yet. You can crete a forward decleration in FeralFramework.h. Also I suggest using proper macros in FeralScene.h also to avoid multiple decelerations.
Since you are using pointer types in header forward decleration will resolve the issue.
// this should be before the class FeralFramework
class FeralScene;

Linker error: Qt and libusb-win32

I try to develop a Qt GUI application which will communicate with a board using USB. The library I use is libusb-win32 v1.2.5.0.
When I compile the application, the following errors occur:
./debug/thread_usb_comm.o: In function `ZN15thread_usb_comm15find_usb_deviceEtt':
thread_usb_comm.cpp:15: undefined reference to 'usb_find_busses'
thread_usb_comm.cpp:16: undefined reference to 'usb_find_devices'
thread_usb_comm.cpp:18: undefined reference to 'usb_get_busses'
thread_usb_comm.cpp:26: undefined reference to 'usb_open'
collect2: ld returned 1 exit status
mingw32-make[1]: [debug/CALSYS11_calib_app.exe] Error 1
mingw32-make: [debug] Error 2
The application code is:
(header file)
#ifndef THREAD_USB_COMM_H
#define THREAD_USB_COMM_H
#include <QThread>
#include <QtDebug>
#include "CALSYS11.h"
#include <lusb0_usb.h>
class thread_usb_comm : public QThread
{
Q_OBJECT
public:
thread_usb_comm();
private:
bool device_connected;
usb_dev_handle *p_usb_device;
bool find_usb_device(
unsigned short vendor_id,
unsigned short product_id
);
};
#endif // THREAD_USB_COMM_H
(source file)
#include "thread_usb_comm.h"
thread_usb_comm::thread_usb_comm()
{
device_connected = false;
}
bool thread_usb_comm::find_usb_device(
unsigned short vendor_id,
unsigned short product_id
)
{
struct usb_bus *bus;
struct usb_device *dev;
usb_find_busses();
usb_find_devices();
for (bus = usb_get_busses(); bus; bus = bus->next)
{
for (dev = bus->devices; dev; dev = dev->next)
{
if ((dev->descriptor.idVendor == vendor_id) &&
(dev->descriptor.idProduct == product_id))
{
qDebug ("Device found");
p_usb_device = usb_open(dev);
if (0 == p_usb_device)
{
qCritical ("Could not open USB device");
return false;
}
device_connected = true;
return true;
}
}
}
qDebug ("Cannot find specified device");
return false;
}
I added the link to the libusb library in the .pro file:
LIBS += -L\path\to\libusb-win32\lib\gcc -lusb
I develop on Windows 7.
Thank you,
Johann
Try to build release instead of debug or the static library is incompatible with compiler version (I faced same issue when I tried to build old static library with MinGW 4.4)

Resources