g ++ — скомпилировать демо-программу c ++ amqp-cpp err, сделать err

Я хочу написать тестовую программу с amqpcppCopernicaMarketingSoftware / AMQP-CPP. Но компилятор (g ++) жалуется:

g++ main.cpp rabbitmq_handler.cpp -std=c++11 -lamqpcpp -lpthread -ldl
In file included from /usr/local/include/amqpcpp/linux_tcp.h:2:0,
from /usr/local/include/amqpcpp/libevent.h:23,
from rabbitmq_handler.h:6,
from main.cpp:1:
/usr/local/include/amqpcpp/linux_tcp/tcpconnection.h:30:30: error: expected class-name before ‘,’ token
private ConnectionHandler,
^
/usr/local/include/amqpcpp/linux_tcp/tcpconnection.h:32:1: error: expected class-name before ‘{’ token
{
^
/usr/local/include/amqpcpp/linux_tcp/tcpconnection.h:39:10: error: ‘shared_ptr’ in namespace ‘std’ does not name a template type
std::shared_ptr<TcpState> _state;
^~~~~~~~~~
/usr/local/include/amqpcpp/linux_tcp/tcpconnection.h:45:5: error: ‘Connection’ does not name a type; did you mean ‘TcpConnection’?
Connection _connection;
^~~~~~~~~~
TcpConnection
/usr/local/include/amqpcpp/linux_tcp/tcpconnection.h:53:34: error: ‘Connection’ has not been declared
virtual uint16_t onNegotiate(Connection *connection, uint16_t interval) override;
^~~~~~~~~~
/usr/local/include/amqpcpp/linux_tcp/tcpconnection.h:61:25: error: ‘Connection’ has not been declared
virtual void onData(Connection *connection, const char *buffer, size_t size) override;
^~~~~~~~~~
/usr/local/include/amqpcpp/linux_tcp/tcpconnection.h:67:30: error: ‘Connection’ has not been declared
virtual void onHeartbeat(Connection *connection) override;
^~~~~~~~~~
/usr/local/include/amqpcpp/linux_tcp/tcpconnection.h:74:26: error: ‘Connection’ has not been declared
virtual void onError(Connection *connection, const char *message) override;
^~~~~~~~~~
/usr/local/include/amqpcpp/linux_tcp/tcpconnection.h:80:30: error: ‘Connection’ has not been declared
virtual void onConnected(Connection *connection) override;
^~~~~~~~~~
/usr/local/include/amqpcpp/linux_tcp/tcpconnection.h:86:27: error: ‘Connection’ has not been declared
virtual void onClosed(Connection *connection) override;
^~~~~~~~~~
/usr/local/include/amqpcpp/linux_tcp/tcpconnection.h:92:26: error: ‘Buffer’ does not name a type
uint64_t parse(const Buffer &buffer)
^~~~~~
/usr/local/include/amqpcpp/linux_tcp/tcpconnection.h:112:46: error: ‘Address’ does not name a type
TcpConnection(TcpHandler *handler, const Address &address);
^~~~~~~
/usr/local/include/amqpcpp/linux_tcp/tcpconnection.h:53:22: error: ‘virtual uint16_t AMQP::TcpConnection::onNegotiate(int*, uint16_t)’ marked ‘override’, but does not override
virtual uint16_t onNegotiate(Connection *connection, uint16_t interval) override;
^~~~~~~~~~~
/usr/local/include/amqpcpp/linux_tcp/tcpconnection.h:61:18: error: ‘virtual void AMQP::TcpConnection::onData(int*, const char*, size_t)’ marked ‘override’, but does not override
virtual void onData(Connection *connection, const char *buffer, size_t size) override;
^~~~~~
/usr/local/include/amqpcpp/linux_tcp/tcpconnection.h:67:18: error: ‘virtual void AMQP::TcpConnection::onHeartbeat(int*)’ marked ‘override’, but does not override
virtual void onHeartbeat(Connection *connection) override;
^~~~~~~~~~~
/usr/local/include/amqpcpp/linux_tcp/tcpconnection.h:74:18: error: ‘virtual void AMQP::TcpConnection::onError(int*, const char*)’ marked ‘override’, but does not override
virtual void onError(Connection *connection, const char *message) override;
^~~~~~~
/usr/local/include/amqpcpp/linux_tcp/tcpconnection.h:80:18: error: ‘virtual void AMQP::TcpConnection::onConnected(int*)’ marked ‘override’, but does not override
virtual void onConnected(Connection *connection) override;
^~~~~~~~~~~
/usr/local/include/amqpcpp/linux_tcp/tcpconnection.h:86:18: error: ‘virtual void AMQP::TcpConnection::onClosed(int*)’ marked ‘override’, but does not override
virtual void onClosed(Connection *connection) override;
^~~~~~~~
/usr/local/include/amqpcpp/linux_tcp/tcpconnection.h: In member function ‘uint64_t AMQP::TcpConnection::parse(const int&)’:
/usr/local/include/amqpcpp/linux_tcp/tcpconnection.h:95:16: error: ‘_connection’ was not declared in this scope
return _connection.parse(buffer);
^~~~~~~~~~~
/usr/local/include/amqpcpp/linux_tcp/tcpconnection.h:95:16: note: suggested alternative: ‘TcpConnection’
return _connection.parse(buffer);
^~~~~~~~~~~
TcpConnection
/usr/local/include/amqpcpp/linux_tcp/tcpconnection.h: In member function ‘bool AMQP::TcpConnection::close()’:
/usr/local/include/amqpcpp/linux_tcp/tcpconnection.h:154:16: error: ‘_connection’ was not declared in this scope
return _connection.close();
^~~~~~~~~~~
/usr/local/include/amqpcpp/linux_tcp/tcpconnection.h:154:16: note: suggested alternative: ‘TcpConnection’
return _connection.close();
^~~~~~~~~~~
TcpConnection
/usr/local/include/amqpcpp/linux_tcp/tcpconnection.h: In member function ‘uint32_t AMQP::TcpConnection::maxFrame() const’:
/usr/local/include/amqpcpp/linux_tcp/tcpconnection.h:163:16: error: ‘_connection’ was not declared in this scope
return _connection.maxFrame();
^~~~~~~~~~~
/usr/local/include/amqpcpp/linux_tcp/tcpconnection.h:163:16: note: suggested alternative: ‘TcpConnection’
return _connection.maxFrame();
^~~~~~~~~~~
TcpConnection
/usr/local/include/amqpcpp/linux_tcp/tcpconnection.h: In member function ‘uint32_t AMQP::TcpConnection::expected() const’:
/usr/local/include/amqpcpp/linux_tcp/tcpconnection.h:172:16: error: ‘_connection’ was not declared in this scope
return _connection.expected();
^~~~~~~~~~~
/usr/local/include/amqpcpp/linux_tcp/tcpconnection.h:172:16: note: suggested alternative: ‘TcpConnection’
return _connection.expected();
^~~~~~~~~~~
TcpConnection
/usr/local/include/amqpcpp/linux_tcp/tcpconnection.h: In member function ‘std::size_t AMQP::TcpConnection::channels() const’:
/usr/local/include/amqpcpp/linux_tcp/tcpconnection.h:182:16: error: ‘_connection’ was not declared in this scope
return _connection.channels();
^~~~~~~~~~~
/usr/local/include/amqpcpp/linux_tcp/tcpconnection.h:182:16: note: suggested alternative: ‘TcpConnection’
return _connection.channels();
^~~~~~~~~~~
TcpConnection
/usr/local/include/amqpcpp/linux_tcp/tcpconnection.h: In member function ‘bool AMQP::TcpConnection::heartbeat()’:
/usr/local/include/amqpcpp/linux_tcp/tcpconnection.h:197:16: error: ‘_connection’ was not declared in this scope
return _connection.heartbeat();
^~~~~~~~~~~
/usr/local/include/amqpcpp/linux_tcp/tcpconnection.h:197:16: note: suggested alternative: ‘TcpConnection’
return _connection.heartbeat();
^~~~~~~~~~~
TcpConnection
In file included from /usr/local/include/amqpcpp/linux_tcp.h:3:0,
from /usr/local/include/amqpcpp/libevent.h:23,
from rabbitmq_handler.h:6,
from main.cpp:1:
/usr/local/include/amqpcpp/linux_tcp/tcpchannel.h: At global scope:
/usr/local/include/amqpcpp/linux_tcp/tcpchannel.h:24:1: error: expected class-name before ‘{’ token
{
^
/usr/local/include/amqpcpp/linux_tcp/tcpchannel.h: In constructor ‘AMQP::TcpChannel::TcpChannel(AMQP::TcpConnection*)’:
/usr/local/include/amqpcpp/linux_tcp/tcpchannel.h:35:9: error: class ‘AMQP::TcpChannel’ does not have any field named ‘Channel’
Channel(&connection->_connection) {}
^~~~~~~
/usr/local/include/amqpcpp/linux_tcp/tcpchannel.h:35:30: error: ‘class AMQP::TcpConnection’ has no member named ‘_connection’; did you mean ‘TcpConnection’?
Channel(&connection->_connection) {}
^~~~~~~~~~~
TcpConnection
In file included from rabbitmq_handler.h:6:0,
from main.cpp:1:
/usr/local/include/amqpcpp/libevent.h: At global scope:
/usr/local/include/amqpcpp/libevent.h:140:10: error: ‘map’ in namespace ‘std’ does not name a template type
std::map<int,std::unique_ptr<Watcher>> _watchers;
^~~
/usr/local/include/amqpcpp/libevent.h: In member function ‘virtual void AMQP::LibEventHandler::monitor(AMQP::TcpConnection*, int, int)’:
/usr/local/include/amqpcpp/libevent.h:152:21: error: ‘_watchers’ was not declared in this scope
auto iter = _watchers.find(fd);
^~~~~~~~~
/usr/local/include/amqpcpp/libevent.h:152:21: note: suggested alternative: ‘Watcher’
auto iter = _watchers.find(fd);
^~~~~~~~~
Watcher
/usr/local/include/amqpcpp/libevent.h:161:34: error: ‘unique_ptr’ is not a member of ‘std’
_watchers[fd] = std::unique_ptr<Watcher>(new Watcher(_evbase, connection, fd, flags));
^~~~~~~~~~
/usr/local/include/amqpcpp/libevent.h:161:52: error: expected primary-expression before ‘>’ token
_watchers[fd] = std::unique_ptr<Watcher>(new Watcher(_evbase, connection, fd, flags));

g++ версия 7.3.0, система ubuntu16.04, amqpcpp версия 3.1.0.

Мой код, как показано ниже, есть 3 файла, rabbitmq_handler.h, rabbitmq_handler.cpp а также main.cc,

rabbitmq_handler.h

#pragma once

#include <functional>
#include <unistd.h>
#include <event2/event.h>
#include <amqpcpp/libevent.h>
#include <amqpcpp/linux_tcp.h>

class LibEventHandlerMyError : public AMQP::LibEventHandler
{
public:
LibEventHandlerMyError(struct event_base* evbase) : LibEventHandler(evbase), evbase_(evbase) {}
void onError(AMQP::TcpConnection *connection, const char *message) override
{
event_base_loopbreak(evbase_);
}
private:
struct event_base* evbase_ {nullptr};
};int init_rabbitmq_conn();

rabbitmq_handler.cpp

#include <iostream>
#include <amqpcpp.h>
#include "rabbitmq_handler.h"

int init_rabbitmq_conn()
{
auto evbase = event_base_new();
LibEventHandlerMyError hndl(evbase);

AMQP::TcpConnection connection(&hndl, AMQP::Address("amqp://localhost:5672/"));
AMQP::TcpChannel channel(&connection);
channel.onError([&evbase](const char* message)
{
std::cout << "Channel error: " << message << std::endl;
event_base_loopbreak(evbase);
});
channel.declareQueue("hello", AMQP::exclusive)
.onSuccess
(
[&connection](const std::string &name,
uint32_t messagecount,
uint32_t consumercount)
{
std::cout << "Queue: " << name << std::endl;
}
)
.onFinalize
(
[&connection]()
{
std::cout << "Finalize." << std::endl;
connection.close();
}
);
channel.publish("", "hello", "Hello, world!");

event_base_dispatch(evbase);
event_base_free(evbase);

return 0;
}

main.cpp

#include "rabbitmq_handler.h"
int main(){
init_rabbitmq_conn();
return 0;
}

1

Решение

Вы нарушаете правило в руководстве:

После сборки есть два соответствующих файла, которые нужно включить при использовании библиотеки.

+-----------+---------------+
|   File    | Include when? |
+-----------+---------------+
| amqpcpp.h |    Always     |
+-----------+---------------+

Вы должны #include <amqpcpp.h> перед любым #include <amqpcpp/...> в вашем rabbitmq_handler.h.

0

Другие решения

Я не думаю, что вы включили определение для класса ConnectionHandler, найденного в AMQP-CPP / include / amqpcpp / connectionhandler.h **

Иногда ожидается, что вы включите один включаемый файл, который сам включает в себя все необходимые файлы включения. Вам нужно найти этот файл и включить его или продолжать добавлять отсутствующие включаемые файлы, пока он не скомпилируется. У вас есть пример? Какие файлы включают в себя? Большой список или только тот, который включает все остальное?

0

По вопросам рекламы [email protected]