VTK / ITK/ QT - unresolved external symbol error (LNK2001) - c++

On building my code with VTK 7.0 with Qt5.7 and and ITK 4.5 in Visual Studio 2013, I get the error below:
error LNK2001: unresolved external symbol "protected: virtual void __cdecl vtkVRMLSource2::SetNthOutput(int,class vtkDataObject *)" (?SetNthOutput#vtkVRMLSource2##MEAAXHPEAVvtkDataObject###Z)
The code corresponding to this file is this (`vtkVRMLSource2.cxx``):
#include "vtkVRML.h"
#include "vtkVRMLSource2.h"
#include "vtkVRMLImporter.h"
#include "vtkObjectFactory.h"
#include "vtkPolyData.h"
#include "vtkProperty.h"
#include "vtkActorCollection.h"
#include "vtkActor.h"
#include "vtkPointData.h"
#include "vtkCellData.h"
#include "vtkPolyDataMapper.h"
#include "vtkRenderer.h"
#include "vtkTransformPolyDataFilter.h"
#include "vtkAppendPolyData.h"
#include "vtkTransform.h"
#include "vtkUnsignedCharArray.h"
#include "vtkSmartPointer.h"
#include "vtkFloatArray.h"
#include "vtkDataObject.h"
#include <stdio.h>
#include <iostream>
.....
idx = 0;
while ( (actor = actors->GetNextActor()) )
{
mapper = vtkPolyDataMapper::SafeDownCast(actor->GetMapper());
if (mapper)
{
//mapper->GetInput()->Update();
//vtkPolyData *newOutput = vtkPolyData::New();
vtkPolyData *newOutput = mapper->GetInput();
//newOutput->CopyInformation(mapper->GetInput());
this->SetNthOutput(idx, newOutput);
++idx;
newOutput->Delete();
newOutput = NULL;
}
}
And the vtkVRMLSource2.h file is:
#include "vtkAlgorithm.h"
#include "vtkDataObject.h"
class vtkVRMLSource2 : public vtkAlgorithm{
public:
int vtkTypeRevisionMacro(vtkVRMLSource2, vtkAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent);
static vtkVRMLSource2 *New();
int NumberOfOutputs;
vtkSetStringMacro(FileName)
vtkGetStringMacro(FileName)
int GetNumberOfOutputs();
vtkPolyData* GetOutput(int idx);
vtkPolyData* GetOutput() { return this->GetOutput(0);}
vtkSetMacro(Color,int) // usage example: this->SetColor(1);
vtkGetMacro(Color,int)
vtkBooleanMacro(Color,int)
vtkSetMacro(Append,int) // usage example: this->SetAppend(1);
vtkGetMacro(Append,int)
vtkBooleanMacro(Append,int)
protected:
vtkVRMLSource2();
~vtkVRMLSource2();
void Execute();
void InitializeImporter();
void CopyImporterToOutputs();
char* FileName;
vtkVRMLImporter *Importer;
int Color;
int Append;
virtual void SetNthOutput(int num, vtkDataObject *output);
private:
vtkVRMLSource2(const vtkVRMLSource2&);
void operator=(const vtkVRMLSource2&);
};
I have linked all the proper VTK, ITK and Qt libraries in VS.
Could you please help me?

You need to provide definition for void SetNthOutput(int num, vtkDataObject *output) which you declared in your header file. You could do it by adding this to vtkVRMLSource2.cxx:
void vtkVRMLSource2::SetNthOutput(int num, vtkDataObject *output)
{
//code goes here
}

Related

Undefined reference when compiling when using header and cpp file with templates in one of them

I've been trying to compile my project and I've encountered some problems when trying so. The error in particular that appears is:
[build] /usr/bin/ld: CMakeFiles/robot_control.dir/main.cpp.o:(.data.rel.ro._ZTVN4comm15cameraInterfaceE[_ZTVN4comm15cameraInterfaceE]+0x10): undefined reference to `comm::Interface<cv::Mat>::callbackMsg()'
My project is organized right now as it follows:
-${HOME_WORKSPACE}
|-main.cpp
|-src
|-communication.cpp
|-communication.hpp
The header file (communication.hpp) is:
#include <opencv2/opencv.hpp>
#include <gazebo/gazebo_client.hh>
#include <gazebo/msgs/msgs.hh>
#include <gazebo/transport/transport.hh>
#include <algorithm>
#ifndef COMM_GUARD
#define COMM_GUARD
namespace comm
{
struct lidarMsg
{
float angle_min, angle_increment, range_min, range_max;
int nranges, nintensities;
std::vector<int> ranges;
};
template <typename T>
class Interface
{
public:
Interface() : received{false} {};
virtual void callbackMsg();
bool receptionAccomplished()
{
return this -> received;
}
T checkReceived()
{
return this -> elementReceived;
}
protected:
bool received;
T elementReceived;
};
class cameraInterface : public Interface<cv::Mat>
{
public:
void callbackMsg(ConstImageStampedPtr &msg);
};
class lidarInterface : public Interface<lidarMsg>
{
public:
void callbackMsg(ConstLaserScanStampedPtr &msg);
};
}
#endif
The source file (communication.cpp) is:
#include <opencv2/opencv.hpp>
#include <algorithm>
#include <iostream>
#include "communication.hpp"
#ifndef COMM_CPP_GUARD
#define COMM_CPP_GUARD
namespace comm
{
void cameraInterface::callbackMsg(ConstImageStampedPtr &msg)
{
std::size_t width = msg->image().width();
std::size_t height = msg->image().height();
const char *data = msg->image().data().c_str();
cv::Mat im(int(height), int(width), CV_8UC3, const_cast<char *>(data));
im = im.clone();
cv::cvtColor(im, im, cv::COLOR_RGB2BGR);
this->elementReceived = im;
received = true;
}
void lidarInterface::callbackMsg(ConstLaserScanStampedPtr &msg) {
this->elementReceived.angle_min = float(msg->scan().angle_min());
this->elementReceived.angle_increment = float(msg->scan().angle_step());
this->elementReceived.range_min = float(msg->scan().range_min());
this->elementReceived.range_max = float(msg->scan().range_max());
this->elementReceived.nranges = msg->scan().ranges_size();
this->elementReceived.nintensities = msg->scan().intensities_size();
for (int i = 0; i < this->elementReceived.nranges; i++)
{
if (this->elementReceived.ranges.size() <= i)
{
this->elementReceived.ranges.push_back(std::min(float(msg->scan().ranges(i)), this->elementReceived.range_max));
}
else
{
this->elementReceived.ranges[i] = std::min(float(msg->scan().ranges(i)), this->elementReceived.range_max);
}
}
}
}
#endif
The main file(main.cpp) includes the following header:
#include <gazebo/gazebo_client.hh>
#include <gazebo/msgs/msgs.hh>
#include <gazebo/transport/transport.hh>
#include <opencv2/opencv.hpp>
#include <opencv2/calib3d.hpp>
#include <iostream>
#include <stdlib.h>
#include "src/communication.hpp"
I included the part of the #ifndef /#define /#endif since it is a solution that I found to this kind of problem in other problem. I've been toggling the CMakeLists.txt file but still no solution that could solve this error.
You can't do this:
virtual void callbackMsg();
You have to actually provide the implementation for all template methods within the .h file.

"error LNK2019: unresolved external symbol "public: __thiscall : constructor" concern [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 7 years ago.
I am currently trying to create a simple implementation of a Module class and a Student class in c++. These classes will incorporate specific modules and the individual students enrolled in them. However, I can't seem to get round this particular error message whenever I try to make a Module or Student object.
It will probably be something simple I missed but I have uploaded my header and source files below. Please help, this is driving me crazy. Thanks in advance.
student.h:
#include "stdafx.h"
#include <string>
class Student {
public:
Student(std::string, std::string, int);
std::string getName() const { return name; }
std::string getDegree() const { return degree; }
int getLevel() const { return level; }
private:
std::string name;
std::string degree;
int level;
};
module.cpp:
// student.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "module.h"
#include <vector>
#include <iostream>
#include <string>
using namespace std;
void Module::enrol_student(Student studentY) {
students.push_back(studentY);
}
void Module::attendance_register() {
string nameX;
cout << "Attendance Register:\n" << endl;
for (int i = 0; i < students.size(); i++) {
Student studentX = students.at(i);
nameX = studentX.getName();
cout << nameX << endl;
}
}
module.h:
#include "stdafx.h"
#include "student.h"
#include <string>
#include <vector>
class Module {
public:
Module(std::string, std::string, std::vector<Student>);
std::string getModCode() { return modCode; }
std::string getModTitle() { return modTitle; }
void attendance_register();
void enrol_student(Student);
private:
std::string modCode;
std::string modTitle;
std::vector<Student> students;
};
testCode.cpp
// testCode.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
#include "module.h"
#include <vector>
#include <iostream>
#include <string>
using namespace std;
int main() {
//Initial Test Data
Student student1("Arthur Smith", "Computer Science", 1);
return 0;
}
You need to define the constructors you declared in your classes. In student.cpp you need something like this:
Student::Student(std::string name, std::string degree, int level) : name(name), degree(degree), level(level)
{
}
This will initialise the members with the values provided.
And similar for Module.

error LNK2019: unresolved external symbol "public: void __thiscall Button::ButtonInit" [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 7 years ago.
I've been going through a C++/SFML tutorial (http://www.gamefromscratch.com/page/Game-From-Scratch-CPP-Edition.aspx) and, having reached the end, started altering the code to try out various things and get more comfortable both with C++ and SFML.
For the menu screen, I decided to create an object for buttons. To this end I created Button.cpp and Button.h, then linked to Button.h in the MainMenu.h file. I added Button button_play as a public member of class MainMenu, however when I call a Button function (for example: button_play.ButtonInit("new-game");), I receive the error: error LNK2019: unresolved external symbol "public: void __thiscall Button::ButtonInit(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?ButtonInit#Button##QAEXV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z) referenced in function "public: enum MainMenu::MenuResult __thiscall MainMenu::Show(class sf::RenderWindow &)" (?Show#MainMenu##QAE?AW4MenuResult#1#AAVRenderWindow#sf###Z)
I've done a lot of searching around this, and most of the answers I've found revolve around not implementing class member functions correctly, however as far as I can tell I am doing it correctly. I am, however, very new to C++, so it's possible that I'm just missing something.
Here's my code:
MainMenu.h
#pragma once
#include "SFML\Window.hpp"
#include "SFML\Graphics.hpp"
#include "GameObjectManager.h"
#include "Button.h"
#include <list>
class MainMenu
{
public:
MainMenu(){};
~MainMenu() {};
enum MenuResult { Nothing, Exit, Play };
const static GameObjectManager& GetGameObjectManager();
struct MenuItem
{
public:
sf::Rect<int> rect;
MenuResult action;
};
MenuResult Show(sf::RenderWindow& window);
static GameObjectManager _gameObjectManager;
Button button_play;
private:
MenuResult GetMenuResponse(sf::RenderWindow& window);
MenuResult HandleClick(int x, int y);
std::list<MenuItem> _menuItems;
};
MainMenu.cpp (this is quite long; I've only included the function that calls ButtonInit() and the function that Show() returns - if you need to see more, let me know and I can include the rest of the code for this file)
#include "stdafx.h"
#include "MainMenu.h"
#include "ServiceLocator.h"
#include "Button.h"
MainMenu::MenuResult MainMenu::Show(sf::RenderWindow& window)
{
button_play.ButtonInit("new-game");
return GetMenuResponse(window);
}
MainMenu::MenuResult MainMenu::GetMenuResponse(sf::RenderWindow& window)
{
sf::Event menuEvent;
while(42 != 43)
{
while(window.pollEvent(menuEvent))
{
if(menuEvent.type == sf::Event::MouseMoved)
{
button_play.Update(window);
}
if(menuEvent.type == sf::Event::MouseButtonPressed)
{
if(ServiceLocator::GetAudio()->IsSongPlaying())
{
ServiceLocator::GetAudio()->StopAllSounds();
}
return HandleClick(menuEvent.mouseButton.x,menuEvent.mouseButton.y);
}
if(menuEvent.type == sf::Event::Closed)
{
return Exit;
}
}
}
}
Button.h
#pragma once
class Button
{
public:
Button() {};
~Button() {};
void ButtonInit(std::string name);
void Update(sf::RenderWindow & rw);
};
Button.cpp
#include "StdAfx.h"
#include "Button.h"
void Button::ButtonInit(std::string name)
{
}
void Button::Update(sf::RenderWindow & rw)
{
}
stdafx.h (probably don't need to see this, but just in case)
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
// TODO: reference additional headers your program requires here
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/Audio.hpp>
#include <map>
#include <iostream>
#include <cassert>
#include <string>
Any help would be appreciated.
I assume, you have both classes in the same project.
The linker-message tells you, that the linker does not find a fitting function definition.
So my guess would be ... the linker cannot find a fitting overload of the function. "new-game" is a const char* and it is not a std::string.
a) change your method signature to
void ButtonInit(const char* name);
or
b) call your method like:
button_play.ButtonInit(std::string("new-game"));

Really basic class won't build

Can someone please tell me what is wrong with this code? I don't get it at all..
I am trying to generate an object out of class "T_Tsunami".
The errors I get are:
"error LNK2019: unresolved external symbol "public: __thiscall T_Tsunami::~T_Tsunami(void)" (??1T_Tsunami##QAE#XZ) referenced in function _main"
and
"fatal error LNK1120: 1 unresolved externals".
Header:
#include <string>
using std::string;
#include<vector>
class T_Tsunami
{
public:
// Constructor with default arguments
T_Tsunami (const int nl = 100, const string="T_Tsunami");
~T_Tsunami(); // destructor
void setNL(int);
void setNaam(string);
private:
string Naam;
int Golf_NL;
};
cpp-file:
#include <vector>
#include <iostream>
#include <fstream>
#include <cmath>
#include "T_Tsunami.h"
T_Tsunami::T_Tsunami (const int nl, const string nieuwe_naam)
{
setNL(nl);
setNaam(nieuwe_naam);
}
void T_Tsunami::setNL(int nl)
{
Golf_NL = nl;
}
void T_Tsunami::setNaam(string nieuwe_naam)
{
Naam = nieuwe_naam;
}
Main:
#include <vector>
#include <iostream>
#include <fstream>
#include <cmath>
#include"T_Tsunami.h"
int main() {
T_Tsunami myTsunami;
}
Also I don't know if I need to put a return statement in the main, I did try that but it doesn't solve my problem.
You did not define the destructor, such as:
T_Tsunami::~T_Tsunami()
{
}

Error 21 error LNK2019: unresolved external symbol:.... referenced in function:....

I tried to create a .h file starting to a .cpp flie. I'm quite sure that the header is correct, but when i try to use the functions of the .cpp file in an other of my project I have a lot of link problems. So I attached the files here, surely someone can give me some solutions. The first solution of check the properties of the project, properties->linker->additional libraries, I have already done.
there are the .cpp files:
IfacomAmqSender.cpp
#include <activemq/library/ActiveMQCPP.h>
#include <decaf/lang/Thread.h>
#include <decaf/lang/Runnable.h>
#include <decaf/util/concurrent/CountDownLatch.h>
#include <decaf/lang/Integer.h>
#include <decaf/lang/Long.h>
#include <decaf/lang/System.h>
#include <activemq/core/ActiveMQConnectionFactory.h>
#include <activemq/util/Config.h>
#include <cms/Connection.h>
#include <cms/Session.h>
#include <cms/TextMessage.h>
#include <cms/BytesMessage.h>
#include <cms/MapMessage.h>
#include <cms/ExceptionListener.h>
#include <cms/MessageListener.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <memory>
using namespace activemq::core;
using namespace decaf::util::concurrent;
using namespace decaf::util;
using namespace decaf::lang;
using namespace cms;
using namespace std;
class IfacomAmqSender : public ExceptionListener{
private:
CountDownLatch m_latch;
CountDownLatch m_doneLatch;
Connection* m_connection;
Session* m_session;
Destination* m_destination;
MessageConsumer* m_consumer;
MessageProducer* m_producer;
std::auto_ptr<TextMessage> m_message;
long m_waitMillis;
bool m_useTopic;
bool m_sessionTransacted;
std::string m_brokerURI;
std::string m_destName;
DeliveryMode m_message_delivery_mode;
int m_message_priority;
private:
//IfacomAmqSender(const IfacomAmqSender&);
//IfacomAmqSender& operator=(const IfacomAmqSender&);
public:
IfacomAmqSender(const std::string& brokerURI, int numMessages, bool useTopic = false, bool sessionTransacted = false, const std::string& destName = "IFACOM-CMS", int waitMillis = 1000) :
m_latch(1),
m_doneLatch(numMessages),
m_connection(NULL),
m_session(NULL),
m_destination(NULL),
m_consumer(NULL),
m_waitMillis(waitMillis),
m_useTopic(useTopic),
m_sessionTransacted(sessionTransacted),
m_destName(destName),
m_brokerURI(brokerURI) {
}
IfacomAmqSender(const std::string& brokerURI, bool useTopic = false, bool sessionTransacted = false, const std::string& destName = "IFACOM-CMS") :
m_latch(1),
m_doneLatch(1),
m_connection(NULL),
m_session(NULL),
m_destination(NULL),
m_consumer(NULL),
m_waitMillis(1000),
m_useTopic(useTopic),
m_sessionTransacted(sessionTransacted),
m_destName(destName),
m_brokerURI(brokerURI) {
}
virtual ~IfacomAmqSender() {
cleanup();
}
void close() {
this->cleanup();
}
void waitUntilReady() {
m_latch.await();
}
//------ Init connexion ---------------
void createConnection()
{
// Create a ConnectionFactory
auto_ptr<ConnectionFactory> connectionFactory(ConnectionFactory::createCMSConnectionFactory(m_brokerURI));
// Create a Connection
m_connection = connectionFactory->createConnection();
m_connection->start();
m_connection->setExceptionListener(this);
}
void createSession()
{
// Create a Session
if (this->m_sessionTransacted == true) {
m_session = m_connection->createSession(Session::SESSION_TRANSACTED);
} else {
m_session = m_connection->createSession(Session::AUTO_ACKNOWLEDGE);
}
}
void createDestination()
{
// Create the destination (Topic or Queue)
if (m_useTopic) {
m_destination = m_session->createTopic(m_destName);
} else {
m_destination = m_session->createQueue(m_destName);
}
}
void createProducer()
{
m_producer = m_session->createProducer(m_destination);
m_producer->setDeliveryMode(DeliveryMode::NON_PERSISTENT);
}
void initConnection() {
try {
createConnection();
// Create the session
createSession();
// Create the destination (Topic or Queue)
createDestination();
// Create a MessageProducer from the Session to the Topic or Queue
createProducer();
m_producer->setDeliveryMode(DeliveryMode::NON_PERSISTENT);
// Indicate we are ready for messages.
m_latch.countDown();
// Wait while asynchronous messages come in.
m_doneLatch.await(m_waitMillis);
} catch (CMSException& e) {
// Indicate we are ready for messages.
//latch.countDown();
e.printStackTrace();
}
}
virtual void sendMessage(string text) {
try {
std::auto_ptr<TextMessage> message(m_session->createTextMessage(text));
// to set a property
////message->setIntProperty("Integer", ix);
m_producer->send(message.get());
message->setCMSTimestamp(System::currentTimeMillis());
} catch (CMSException& e) {
e.printStackTrace();
}
}
// Send a ActiveMQ Message
virtual void sendMessage(std::auto_ptr<TextMessage> amq_message) {
try {
amq_message->setCMSTimestamp(System::currentTimeMillis());
m_producer->send(amq_message.get());
} catch (CMSException& e) {
e.printStackTrace();
}
}
//--------------------------------------------------
// If something bad happens you see it here as this class is also been
// registered as an ExceptionListener with the connection.
virtual void onException(const CMSException& ex AMQCPP_UNUSED) {
printf("CMS Exception occurred. Shutting down client.\n");
ex.printStackTrace();
exit(1);
}
// Message Priority (0:Lowest - 9:Highest)
void setPriority(int priority){m_message_priority = priority;}
int getPriority(){return m_message_priority;}
// Message Delivery Mode
void setDeliveryMode(DeliveryMode delivery_mode){m_message_delivery_mode = delivery_mode;}
DeliveryMode getDeliveryMode(){return m_message_delivery_mode;}
Session* getSession()
{
return m_session;
}
private:
void cleanup() {
if (m_connection != NULL) {
try {
m_connection->close();
} catch (cms::CMSException& ex) {
ex.printStackTrace();
}
}
// Destroy resources.
try {
delete m_destination;
m_destination = NULL;
delete m_consumer;
m_consumer = NULL;
delete m_session;
m_session = NULL;
delete m_connection;
m_connection = NULL;
} catch (CMSException& e) {
e.printStackTrace();
}
}
};
mainwindow.cpp file:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "IfacomAmqSender.h"
#include <activemq/library/ActiveMQCPP.h>
#include <decaf/lang/Thread.h>
#include <decaf/lang/Runnable.h>
#include <decaf/util/concurrent/CountDownLatch.h>
#include <decaf/lang/Integer.h>
#include <decaf/lang/Long.h>
#include <decaf/lang/System.h>
#include <activemq/core/ActiveMQConnectionFactory.h>
#include <activemq/util/Config.h>
#include <cms/Connection.h>
#include <cms/Session.h>
#include <cms/TextMessage.h>
#include <cms/BytesMessage.h>
#include <cms/MapMessage.h>
#include <cms/ExceptionListener.h>
#include <cms/MessageListener.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <memory>
#include <qstring.h>
#include <QTextStream>
#include <QMessageBox>
using namespace activemq::core;
using namespace decaf::util::concurrent;
using namespace decaf::util;
using namespace decaf::lang;
using namespace cms;
using namespace std;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
activemq::library::ActiveMQCPP::initializeLibrary();
{
std::string brokerURI;
brokerURI = "failover://(tcp://localhost:61613?wireFormat=stomp)"; // localhost
// brokerURI = "failover://(tcp://localhost:61616)"; // localhost
// Queue name
std::string destName = "IFACOM-CMS";
// Queue or Topic
bool useTopics = false; // true=Topic, false=Queue
// SESSION_TRANSACTED or AUTO_ACKNOWLEDGE
bool sessionTransacted = false; // if true, commit all messages
long long startTime = System::currentTimeMillis();
// ***** Initialisation **************************************************************
IfacomAmqSender IfacomMessageBroker(brokerURI, useTopics, sessionTransacted, destName);
IfacomMessageBroker.initConnection();
//****** Send message ******************************************************
std::string text = "My IFaCOM message";
// Customized message
try{
std::auto_ptr<TextMessage> message(IfacomMessageBroker.getSession()->createTextMessage(text));
message->setCMSTimestamp(System::currentTimeMillis());
message->setStringProperty("MyProperty", "test");
IfacomMessageBroker.sendMessage(message);
} catch (CMSException& e) {
e.printStackTrace();
}
// Simple text message
IfacomMessageBroker.sendMessage(text);
long long endTime = System::currentTimeMillis();
double totalTime = (double)(endTime - startTime) / 1000.0;
// Close the connection
IfacomMessageBroker.close();
ui->label->setText(QString::fromStdString(text));
}
// To Do at the end
activemq::library::ActiveMQCPP::shutdownLibrary();
}
main.cpp file:
#include "ifacomamqsender.h"
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
there are the header files:
IfacomAmqSender.h file:
#ifndef _IfacomAmqSender_h
#define _IfacomAmqSender_h
#include <activemq/library/ActiveMQCPP.h>
#include <decaf/lang/Thread.h>
#include <decaf/lang/Runnable.h>
#include <decaf/util/concurrent/CountDownLatch.h>
#include <decaf/lang/Integer.h>
#include <decaf/lang/Long.h>
#include <decaf/lang/System.h>
#include <activemq/core/ActiveMQConnectionFactory.h>
#include <activemq/util/Config.h>
#include <cms/Connection.h>
#include <cms/Session.h>
#include <cms/TextMessage.h>
#include <cms/BytesMessage.h>
#include <cms/MapMessage.h>
#include <cms/ExceptionListener.h>
#include <cms/MessageListener.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <memory>
using namespace activemq::core;
using namespace decaf::util::concurrent;
using namespace decaf::util;
using namespace decaf::lang;
using namespace cms;
using namespace std;
class IfacomAmqSender{
private:
CountDownLatch m_latch;
CountDownLatch m_doneLatch;
Connection* m_connection;
Session* m_session;
Destination* m_destination;
MessageConsumer* m_consumer;
MessageProducer* m_producer;
std::auto_ptr<TextMessage> m_message;
long m_waitMillis;
bool m_useTopic;
bool m_sessionTransacted;
std::string m_brokerURI;
std::string m_destName;
DeliveryMode m_message_delivery_mode;
int m_message_priority;
IfacomAmqSender(const IfacomAmqSender&);
IfacomAmqSender& operator=(const IfacomAmqSender&);
public:
IfacomAmqSender(const std::string&, int, bool, bool, const std::string&, int);
IfacomAmqSender(const std::string&, bool, bool, const std::string&);
virtual ~IfacomAmqSender();
void close();
void waitUntilReady();
void cleanup();
// KH
void createConnection();
void createSession();
void createDestination();
void createProducer();
void initConnection();
virtual void sendMessage(string);
// Send a ActiveMQ Message
virtual void sendMessage(std::auto_ptr<TextMessage>);
//--------------------------------------------------
// If something bad happens you see it here as this class is also been
// registered as an ExceptionListener with the connection.
virtual void onException(const CMSException&) ;
// Message Priority (0:Lowest - 9:Highest)
void setPriority(int);
int getPriority();
// Message Delivery Mode
void setDeliveryMode(DeliveryMode);
DeliveryMode getDeliveryMode();
Session* getSession();
};
#endif
mainwindow.h file:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_pushButton_clicked();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
THE ERRORS ARE:
Error 21 error LNK2019: unresolved external symbol "public: __thiscall IfacomAmqSender::IfacomAmqSender(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,bool,bool,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0IfacomAmqSender##QAE#ABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##_N10#Z) referenced in function "private: void __thiscall MainWindow::on_pushButton_clicked(void)" (?on_pushButton_clicked#MainWindow##AAEXXZ) C:\Users\Marco\Desktop\Activemq\ReleaseVersions\GUI-CMS\mainwindow.obj GUI-CMS
Error 22 error LNK2019: unresolved external symbol "public: virtual __thiscall IfacomAmqSender::~IfacomAmqSender(void)" (??1IfacomAmqSender##UAE#XZ) referenced in function __catch$?on_pushButton_clicked#MainWindow##AAEXXZ$0 C:\Users\Marco\Desktop\Activemq\ReleaseVersions\GUI-CMS\mainwindow.obj GUI-CMS
Error 23 error LNK2019: unresolved external symbol "public: void __thiscall IfacomAmqSender::close(void)" (?close#IfacomAmqSender##QAEXXZ) referenced in function __catch$?on_pushButton_clicked#MainWindow##AAEXXZ$0 C:\Users\Marco\Desktop\Activemq\ReleaseVersions\GUI-CMS\mainwindow.obj GUI-CMS
Error 24 error LNK2019: unresolved external symbol "public: void __thiscall IfacomAmqSender::initConnection(void)" (?initConnection#IfacomAmqSender##QAEXXZ) referenced in function "private: void __thiscall MainWindow::on_pushButton_clicked(void)" (?on_pushButton_clicked#MainWindow##AAEXXZ) C:\Users\Marco\Desktop\Activemq\ReleaseVersions\GUI-CMS\mainwindow.obj GUI-CMS
Error 25 error LNK2019: unresolved external symbol "public: virtual void __thiscall IfacomAmqSender::sendMessage(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?sendMessage#IfacomAmqSender##UAEXV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z) referenced in function __catch$?on_pushButton_clicked#MainWindow##AAEXXZ$0 C:\Users\Marco\Desktop\Activemq\ReleaseVersions\GUI-CMS\mainwindow.obj GUI-CMS
Error 26 error LNK2019: unresolved external symbol "public: virtual void __thiscall IfacomAmqSender::sendMessage(class std::auto_ptr<class cms::TextMessage>)" (?sendMessage#IfacomAmqSender##UAEXV?$auto_ptr#VTextMessage#cms###std###Z) referenced in function "private: void __thiscall MainWindow::on_pushButton_clicked(void)" (?on_pushButton_clicked#MainWindow##AAEXXZ) C:\Users\Marco\Desktop\Activemq\ReleaseVersions\GUI-CMS\mainwindow.obj GUI-CMS
Error 27 error LNK2019: unresolved external symbol "public: class cms::Session * __thiscall IfacomAmqSender::getSession(void)" (?getSession#IfacomAmqSender##QAEPAVSession#cms##XZ) referenced in function "private: void __thiscall MainWindow::on_pushButton_clicked(void)" (?on_pushButton_clicked#MainWindow##AAEXXZ) C:\Users\Marco\Desktop\Activemq\ReleaseVersions\GUI-CMS\mainwindow.obj GUI-CMS
Error 28 error LNK1120: 7 unresolved externals C:\Users\Marco\Desktop\Activemq\ReleaseVersions\GUI-CMS\debug\\GUI-CMS.exe GUI-CMS
I do not understand your code. it has two different definitions of class IfacomAmqSender. The first one is
class IfacomAmqSender : public ExceptionListener{
and the second one is
class IfacomAmqSender{
I think the reason of the errors is these duplications of class IfacomAmqSender
Your IfacomAmqSender constructor is declared as follows:
IfacomAmqSender(const std::string&, int, bool, bool, const std::string&, int);
The implementation header is as follows:
IfacomAmqSender(const std::string& brokerURI, int numMessages, bool useTopic = false, bool sessionTransacted = false, const std::string& destName = "IFACOM-CMS", int waitMillis = 1000);
So your implementation declares standard parameter values, while the declaration doesn't. So it's quite random whether at the place of any call, it is known that the function can take standard arguments. Either remove all standard arguments or make sure you declare them the same everywhere, both in declaration and implementation. (My C++ is a bit rusted, I think the main place for it would be the declaration in the .h file).
Oh, and hell, yes: See the other answer. The implementation has another class header around it. So you're actually declaring two classes with the same name. The CPP file usually does not have any class X : public Y declarations in it.