CopernicaMarketingSoftware/AMQP-CPP

undefined reference to `AMQP::TcpConnection::~TcpConnection()'

dineshelavazhagan opened this issue · 10 comments

Facing the error again

/rabbitq/AMQP-CPP/include/mytcpqu.cpp:179: undefined reference to AMQP::TcpConnection::TcpConnection(AMQP::TcpHandler*, AMQP::Address const&)' /usr/bin/ld: /rabbitq/AMQP-CPP/include/mytcpqu.cpp:198: undefined reference to AMQP::TcpConnection::~TcpConnection()'
collect2: error: ld returned 1 exit status

Are you using GCC or something else? And what's your linux command?

g++ -g -Wall -ldl -lpthread -lamqpcpp include/mytcpqu.cpp -o myampp

Undefined reference happens when the g++ can't find a lib. -lamqpcpp will find libamqpcpp.so you can search it on your computer and then tell the g++ your location of libamqpcpp.so.

I tried that but still same error which happened on 4.0.1 #267 problem with connection

Can you provide the smallest possible test program that demonstrates this issue + the compile-command that you use?

I got the same problem, by running the example code provided in the readme I get the same error:

/usr/bin/ld: /tmp/cc3Caghi.o: in function `main':
 undefined reference to `AMQP::TcpConnection::TcpConnection(AMQP::TcpHandler*, AMQP::Address const&)'
/usr/bin/ld:  undefined reference to `AMQP::TcpConnection::~TcpConnection()'
collect2: error: ld returned 1 exit status

To compile the file I used:
g++ -g -Wall -lamqpcpp -lpthread -ldl main.cpp -o main
I also tried to explicitly set the library path and the path to the files to be included by using -Lusr/local/lib and -Iusr/local/include but it didn't work.

A minimal example that in my case reproduce the error is:

// Main function
int main(int argc, char *argv[]) {
    AMQP::TcpConnection connection(nullptr, AMQP::Address("192.168.1.1"));
    return 0;
}

@dineshelavazhagan Did you managed to solve this issue?

Typical, can you run nm /usr/lib/libamqpcpp.so|grep TcpConnection -- and copy/paste the output to www.demangler.com? It is supposed to list TcpConnection::~TcpConnection.

Typical, can you run nm /usr/lib/libamqpcpp.so|grep TcpConnection -- and copy/paste the output to www.demangler.com? It is supposed to list TcpConnection::~TcpConnection.

Yes, it shows TcpConnection::~TcpConnection, this is the complete output

00000000001019f4 W AMQP::TcpConnection::onReceived(AMQP::TcpState*, AMQP::Buffer const&)
000000000010191c W AMQP::TcpConnection::onSecuring(AMQP::TcpState*, ssl_st*)
00000000001018c8 W AMQP::TcpConnection::onConnected(AMQP::TcpState*)
0000000000101834 W AMQP::TcpConnection::onHeartbeat(AMQP::Connection*)
0000000000100d2c T AMQP::TcpConnection::onNegotiate(AMQP::Connection*, unsigned short)
0000000000100cd4 T AMQP::TcpConnection::onProperties(AMQP::Connection*, AMQP::Table const&, AMQP::Table&)
0000000000100b14 T AMQP::TcpConnection::close(bool)
0000000000100dc4 T AMQP::TcpConnection::onData(AMQP::Connection*, char const*, unsigned long)
0000000000101a30 W AMQP::TcpConnection::onIdle(AMQP::TcpState*, int, int)
00000000001010d8 T AMQP::TcpConnection::onLost(AMQP::TcpState*)
0000000000100e0e T AMQP::TcpConnection::onError(AMQP::Connection*, char const*)
0000000000100f68 T AMQP::TcpConnection::onError(AMQP::TcpState*, char const*, bool)
000000000010187e W AMQP::TcpConnection::onReady(AMQP::Connection*)
00000000001009f8 T AMQP::TcpConnection::process(int, int)
0000000000101a8e W AMQP::TcpConnection::expected()
0000000000100f0c T AMQP::TcpConnection::onClosed(AMQP::Connection*)
0000000000101988 W AMQP::TcpConnection::onSecured(AMQP::TcpState*, ssl_st const*)
000000000010050c T AMQP::TcpConnection::TcpConnection(AMQP::TcpHandler*, AMQP::Address const&)
000000000010050c T AMQP::TcpConnection::TcpConnection(AMQP::TcpHandler*, AMQP::Address const&)

000000000010091e T AMQP::TcpConnection::~TcpConnection()
0000000000100802 T AMQP::TcpConnection::~TcpConnection()
0000000000100802 T AMQP::TcpConnection::~TcpConnection()

00000000001009c6 T AMQP::TcpConnection::closed() const
0000000000100962 T AMQP::TcpConnection::fileno() const
0000000000100994 T AMQP::TcpConnection::queued() const
0000000000101a25 W non-virtual thunk to AMQP::TcpConnection::onReceived(AMQP::TcpState*, AMQP::Buffer const&)
000000000010197e W non-virtual thunk to AMQP::TcpConnection::onSecuring(AMQP::TcpState*, ssl_st*)
0000000000101912 W non-virtual thunk to AMQP::TcpConnection::onConnected(AMQP::TcpState*)
0000000000101a84 W non-virtual thunk to AMQP::TcpConnection::onIdle(AMQP::TcpState*, int, int)
00000000001011d9 T non-virtual thunk to AMQP::TcpConnection::onLost(AMQP::TcpState*)
00000000001010ca T non-virtual thunk to AMQP::TcpConnection::onError(AMQP::TcpState*, char const*, bool)
0000000000101ab2 W non-virtual thunk to AMQP::TcpConnection::expected()
00000000001019ea W non-virtual thunk to AMQP::TcpConnection::onSecured(AMQP::TcpState*, ssl_st const*)
000000000010094d T non-virtual thunk to AMQP::TcpConnection::~TcpConnection()
0000000000100911 T non-virtual thunk to AMQP::TcpConnection::~TcpConnection()
0000000000100957 T non-virtual thunk to AMQP::TcpConnection::~TcpConnection()
0000000000100904 T non-virtual thunk to AMQP::TcpConnection::~TcpConnection()
0000000000140610 V typeinfo for AMQP::TcpConnection
0000000000110420 V typeinfo name for AMQP::TcpConnection
000000000013fed0 V vtable for AMQP::TcpConnection

LIttle update, the error does not appear if I compile using:
g++ -g -Wall main.cpp -o main -lamqpcpp -lpthread -ldl
i.e. putting at the end the libraries to link.
It seems that the order of the linked libraries does not matter, what's important is that main.cpp -o main must be before the libraries..
The code seems to work :D , I'll update this post if there are other issues or if this is not the correct solution.