Really basic class won't build - c++

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

Related

error while using std:sort on vector of objects [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 3 years ago.
I have a vector of Person object pointers. I am trying to use std:sort to sort the vector based on the "name" of each object. I am getting an unresolved external symbol error when I try to build and run; can anyone see where I am going wrong? error:
Error LNK2019 unresolved external symbol "public: static bool __cdecl Person::sortByName(class Person *,class Person *)" (?sortByName#Person##SA_NPAV1#0#Z) referenced in function _main Lab1b C:\Users\jayjo\source\repos\Lab1b\Lab1b\Lab1b.obj 1
error
Main cpp:
#include <iostream>
#include "Person.h"
#include "Employee.h"
#include "Customer.h"
#include <vector>
#include <algorithm>
int main()
{
vector<Person*> people;
people.push_back(new Person("Peter"));
people.push_back(new Person("John"));
people.push_back(new Person("David"));
people.push_back(new Person("Aaron"));
sort(people.begin(), people.end(), Person::sortByName);
for (int i = 0; i < people.size(); i++)
{
cout << people[i]->getName() << endl;
}
}
Person.h:
#pragma once
#ifndef Person_H
#define Person_H
using namespace std;
#include <iostream>
class Person
{
public:
Person(string);
virtual void printname();
static bool sortByName(Person* A, Person* B);
string getName();
protected:
string name;
};
#endif // !Person_H
Person.cpp:
#include "Person.h"
using namespace std;
Person::Person(string n)
{
name = n;
}
void Person::printname()
{
cout << "Name: " << name << endl;
}
string Person::getName()
{
return name;
}
static bool sortByName(Person* A, Person* B)
{
return (A->getName().compare(B->getName()));
}
Instead of this:
static bool sortByName(Person* A, Person* B)
{
return (A->getName().compare(B->getName()));
}
This:
bool Person::sortByName(Person* A, Person* B)
{
return (A->getName().compare(B->getName()) != 0);
}
In C++, you declare the class member function as static, but you leave the static keyword off when you define it. Also, the function needs to be defined as a class member (Person::).

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

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
}

"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 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.

C++ "unresolved external symbol" using namespace from different project

I have two projects (call them Test and Intrados). Inside Intrados, I have the following namespace:
#include "Mapper.h"
#include "Director.h"
#include "Driver.h"
#include <iostream>
#include <string>
using namespace std;
namespace IntradosMediator {
void addVehicle(string);
}
void IntradosMediator::addVehicle(string vehicleName) {
Mapper* mapper = Mapper::getInstance();
mapper->addVehicle(vehicleName);
}
From within the Intrados project, calling "IntradosMediator::Mapper(addVehicle)" works just fine; yet, in project Test, the following code produces a link error:
#include "IntradosMediator.cpp"
#include "Mapper.h"
using namespace IntradosMediator;
int main(){
IntradosMediator::addVehicle("Car X");
return 0;
}
The error is:
Test.obj : error LNK2019: unresolved external symbol "public: static class Mapper *
__cdecl Mapper::getInstance(void)" (?getInstance#Mapper##SAPAV1#XZ) referenced in
function "void __cdecl IntradosMediator::addVehicle(class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> >)"
(?addVehicle#IntradosMediator##YAXV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##
std###Z)
I've made sure to add Intrados as a reference for Test, and also included it in the Include Directories. Not sure what to do here, since I'm new to C++. Thanks in advance for any advice.
Edit:
I'm adding the Mapper code here:
//.h
#ifndef MAPPER_H
#define MAPPER_H
#include <string>
using std::string;
class Mapper {
public:
static Mapper* getInstance();
void addVehicle(string);
private:
//this is a singleton
Mapper(){};
};
#endif
//.cpp
#include "Mapper.h"
#include <vector>
#include <iostream>
#include <string>
using namespace std;
vector<string> vehicleList;
Mapper* Mapper::getInstance(){
static Mapper instance;
return &instance;
}
void
Mapper::addVehicle(string vehicleName) {
vehicleList.push_back(vehicleName);
}
The error says the linker can't find Mapper::getInstance (it seems to find your addVehicle function just fine). Might you be failing to include the library that implements "Mapper" in your link?
Could you paste your code for class Mapper?
It seems like you are missing addVehicle function in that class, which is what the compiler is complaining about.