gpt4 book ai didi

c++ - 与应用程序的链接错误

转载 作者:太空狗 更新时间:2023-10-29 21:22:21 24 4
gpt4 key购买 nike

<分区>

我在构建后出现此链接错误,但不知道出处。我检查了链接器属性中的所有外部依赖项,但没有。为您提供 header 和 cpp 的正文:

文件主窗口.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#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 <include/IfacomAmqSender.h>
#include <include/IfacomAmqReceiver.h>

using namespace activemq::core;
using namespace decaf::util::concurrent;
using namespace decaf::util;
using namespace decaf::lang;
using namespace cms;

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
void onMessage(const Message*);
void connectionSender();


private slots:
void on_pushButton_clicked();
void on_pushButton_2_clicked();



private:
Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H

文件主窗口.cpp

#include "include/IfacomAmqSender.h"
#include "include/IfacomAmqReceiver.h"
#include "mainwindow.h"
#include "ui_mainwindow.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>

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}

MainWindow::~MainWindow()
{
delete ui;
}

/*********** Definition m_IfacomMessageBroker ******************/
std::string 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

// Message parametres
int numMess=1; int waitMillis=1000;

// Definition of object m_IfacomMessageBroker
//IfacomAmqSender m_IfacomMessageBroker(brokerURI,numMess, useTopics, sessionTransacted, destName,waitMillis);
IfacomAmqSender* m_IfacomMessageBroker = new IfacomAmqSender(brokerURI,numMess, useTopics, sessionTransacted, destName,waitMillis);
void MainWindow::connectionSender()
{
activemq::library::ActiveMQCPP::initializeLibrary();
// ***** Initialisation **************************************************************
//m_IfacomMessageBroker.initConnection();
m_IfacomMessageBroker->initConnection();
m_IfacomMessageBroker->getSession()->createTextMessage();

//IfacomAmqReceiver IfacomAmqReceiverBroker(brokerURI,10, useTopics, sessionTransacted, destName,2000);
//IfacomAmqReceiverBroker.initConnection();
//IfacomAmqReceiverBroker.getConsumer()->setMessageListener(this);

}

void MainWindow::on_pushButton_clicked()
{
connectionSender();
}

void MainWindow::on_pushButton_2_clicked()
{

}

文件main.cpp

#include "mainwindow.h"
#include <include\IfacomAmqSender.h>
#include <include\IfacomAmqReceiver.h>
#include <QApplication>

int main(int argc, char *argv[])
{
QApplication prog(argc, argv);
MainWindow w;
w.show();

return prog.exec();
}

和链接错误中调用的文件 IfacomAmqSender.h:

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


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;

IfacomAmqSender(const IfacomAmqSender&);
IfacomAmqSender& operator=(const IfacomAmqSender&);

public:


IfacomAmqSender (const std::string&, int, bool,bool,const std::string&,int);
//explicit IfacomAmqSender(const std::string&, int, bool, bool, const std::string&, int);
//IfacomAmqSender(const std::string&, bool, bool, const std::string&);

~IfacomAmqSender();
void close();
void waitUntilReady();
void cleanup();

// KH
void createConnection();
void createSession();
void createDestination();
void createProducer();
void initConnection();

virtual void sendMessage(std::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

文件 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>
#include "IfacomAmqSender.h"

using namespace activemq::core;
using namespace decaf::util::concurrent;
using namespace decaf::util;
using namespace decaf::lang;
using namespace cms;
using namespace std;






IfacomAmqSender::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::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) {
}*/


IfacomAmqSender::~IfacomAmqSender() {
cleanup();
}

void IfacomAmqSender::close() {
this->cleanup();
}

void IfacomAmqSender::waitUntilReady() {
m_latch.await();
}

//------ Init connexion ---------------

void IfacomAmqSender::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 IfacomAmqSender::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 IfacomAmqSender::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 IfacomAmqSender::createProducer()
{
m_producer = m_session->createProducer(m_destination);
m_producer->setDeliveryMode(DeliveryMode::NON_PERSISTENT);
}

void IfacomAmqSender::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();
}
}


void IfacomAmqSender::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
void IfacomAmqSender::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.
void IfacomAmqSender::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 IfacomAmqSender::setPriority(int priority){m_message_priority = priority;}
int IfacomAmqSender::getPriority(){return m_message_priority;}

// Message Delivery Mode
void IfacomAmqSender::setDeliveryMode(DeliveryMode delivery_mode){m_message_delivery_mode = delivery_mode;}
DeliveryMode IfacomAmqSender::getDeliveryMode(){return m_message_delivery_mode;}

Session* IfacomAmqSender::getSession()
{
return m_session;
}


void IfacomAmqSender::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();
}
}

错误是:

Error   2   error LNK2019: unresolved external symbol "public: __thiscall IfacomAmqSender::IfacomAmqSender(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int,bool,bool,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int)" (??0IfacomAmqSender@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H_N10H@Z) referenced in function "void __cdecl `dynamic initializer for 'm_IfacomMessageBroker''(void)" (??__Em_IfacomMessageBroker@@YAXXZ) C:\Users\Marco\Desktop\Activemq\ReleaseVersions\GUI-CMS-SENDER\mainwindow.obj   GUI-CMS-SENDER
Error 3 error LNK2019: unresolved external symbol "public: void __thiscall IfacomAmqSender::initConnection(void)" (?initConnection@IfacomAmqSender@@QAEXXZ) referenced in function "public: void __thiscall MainWindow::connectionSender(void)" (?connectionSender@MainWindow@@QAEXXZ) C:\Users\Marco\Desktop\Activemq\ReleaseVersions\GUI-CMS-SENDER\mainwindow.obj GUI-CMS-SENDER
Error 4 error LNK2019: unresolved external symbol "public: class cms::Session * __thiscall IfacomAmqSender::getSession(void)" (?getSession@IfacomAmqSender@@QAEPAVSession@cms@@XZ) referenced in function "public: void __thiscall MainWindow::connectionSender(void)" (?connectionSender@MainWindow@@QAEXXZ) C:\Users\Marco\Desktop\Activemq\ReleaseVersions\GUI-CMS-SENDER\mainwindow.obj GUI-CMS-SENDER

命令行是:

/OUT:"debug\\GUI-CMS-SENDER.exe" /MANIFEST /NXCOMPAT /PDB:"debug\GUI-CMS-SENDER.pdb" /DYNAMICBASE "qtmaind.lib" "C:\Qt\Qt5.1.1\5.1.1\msvc2012\\lib\Qt5Widgetsd.lib" "C:\Qt\Qt5.1.1\5.1.1\msvc2012\\lib\Qt5Guid.lib" "C:\Qt\Qt5.1.1\5.1.1\msvc2012\\lib\Qt5Cored.lib" "libEGLd.lib" "libGLESv2d.lib" "gdi32.lib" "user32.lib" "Qt5Cored.lib" "Qt5Guid.lib" "libapr-1.lib" "libactivemq-cppd.lib" "ws2_32.lib" "kernel32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /DEBUG /MACHINE:X86 /SAFESEH /PGD:"debug\GUI-CMS-SENDER.pgd" /SUBSYSTEM:WINDOWS /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"Win32\Debug\GUI-CMS-SENDER.exe.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /LIBPATH:"lib" /LIBPATH:"C:\Qt\Qt5.1.1\5.1.1\msvc2012\\lib" /LIBPATH:"\lib" /LIBPATH:"C:\Users\Marco\Desktop\Activemq\ReleaseVersions\GUI-CMS-SENDER\include" /TLBID:1 

This is the command line

Additional Dependencies

Input Linker properties

Here the project

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com