undefined reference when compiling with x86_64-w64-mingw32-g++

165 views
Skip to first unread message

Stephen Hsu

unread,
Oct 31, 2016, 1:03:22 AM10/31/16
to simpleamqpclient-users

Hi,


Anybody ever met such "undefined reference" when using SimpleAmqpClient ?


I've tried to compile mytest.cpp with x86_64-w64-mingw32-g++. Below errors occurred. Actually I've already specified the path to where the SimpleAmqpClient library is with "-L" flag.


$ x86_64-w64-mingw32-g++ -static -static-libgcc -static-libstdc++ -Wl,-Bstatic -lpthread -Wl,-Bdynamic -Wno-deprecated -I/usr/local/include -I/usr/local/include/SimpleAmqpClient -L/usr/local/lib -L/usr/local/lib/pkgconfig -L/usr/x86_64-w64-mingw32/lib -L/usr/lib/gcc/x86_64-w64-mingw32/4.8 -std=gnu++11 -o mytest.out mytest.cpp -lSimpleAmqpClient
/tmp/ccUpsgSe.o:mytest.cpp:(.text+0xc90): undefined reference to `__imp__ZN10AmqpClient7Channel12DeclareQueueERKSsbbbb'
/tmp/ccUpsgSe.o:mytest.cpp:(.text+0xd0d): undefined reference to `__imp__ZN10AmqpClient12BasicMessage7ReplyToERKSs'
/tmp/ccUpsgSe.o:mytest.cpp:(.text+0xd6d): undefined reference to `__imp__ZN10AmqpClient7Channel12BasicPublishERKSsS2_N5boost10shared_ptrINS_12BasicMessageEEEbb'
/tmp/ccUpsgSe.o:mytest.cpp:(.text+0xe0c): undefined reference to `__imp__ZN10AmqpClient7Channel12BasicConsumeERKSsS2_bbbt'
/tmp/ccUpsgSe.o:mytest.cpp:(.text+0xe5a): undefined reference to `__imp__ZN10AmqpClient7Channel19BasicConsumeMessageERKSs'
/tmp/ccUpsgSe.o:mytest.cpp:(.text+0xea5): undefined reference to `__imp__ZNK10AmqpClient12BasicMessage4BodyEv'
/usr/bin/x86_64-w64-mingw32-ld: /tmp/ccUpsgSe.o: bad reloc address 0x2c in section `.rdata'
collect2: error: ld returned 1 exit status

$ ls /usr/local/lib | grep Simple
libSimpleAmqpClient.a
libSimpleAmqpClient.so libSimpleAmqpClient.so.2 libSimpleAmqpClient.so.2.4.0


Part of mytest.cpp is as below,

#include <iostream>
#include <fstream>
#include <ostream>
#include <strstream>
#include "SimpleAmqpClient/SimpleAmqpClient.h"

.......

std::string dama_upload(......) {
    // set up a channel to amqp
    AmqpClient::Channel::ptr_t channel = AmqpClient::Channel::Create(host, port,
                                                                     username, password,
                                                                     vhost);
    // declare a unique callback queue
    const std::string callback_queue = channel->DeclareQueue("");

    ........
}



I've tried several ways after searching Google. But none of the solutions worked.


I guess it is the linker issue. But still cannot find out a way to solve this problem.


Alan Antonuk

unread,
Oct 31, 2016, 1:32:24 AM10/31/16
to Stephen Hsu, simpleamqpclient-users
What other solutions have you tried?

If you're trying to build a completely statically linked binary, you're also going to need to link against rabbitmq-c, and a few boost libraries as well (both of which will need to be statically built).

-Alan

--
You received this message because you are subscribed to the Google Groups "simpleamqpclient-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to simpleamqpclient-...@googlegroups.com.
To post to this group, send email to simpleamqpc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/simpleamqpclient-users/55334677-22d7-47f2-9c25-6319207c5931%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Stephen Hsu

unread,
Oct 31, 2016, 3:53:02 AM10/31/16
to simpleamqpclient-users
Hi Alan,

Thanks for your reply.

I start a container based on ubuntu/trusty to create a clean env for compiling.

All the dependencies have already been installed. And I compiled my source code with `-L`, `-I` flags. The `libSimpleAmqpClient.a` is compiled successfully. 

Attached my source code and command lines history.

I wonder where I went wrong.
To unsubscribe from this group and stop receiving emails from it, send an email to simpleamqpclient-users+unsub...@googlegroups.com.
log-history.log
mytest.cpp

Alan Antonuk

unread,
Nov 1, 2016, 1:55:14 AM11/1/16
to Stephen Hsu, simpleamqpclient-users
Check to see if libSimpleAmqpClient.a has the symbols that seem to be missing? (use the nm utility).  Make sure that its compiled for the right target (IOW: libSimpleAmqpClient and all of it's dependencies need to be compiled with x86_64-w64-mingw32-g++.

To unsubscribe from this group and stop receiving emails from it, send an email to simpleamqpclient-...@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "simpleamqpclient-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to simpleamqpclient-...@googlegroups.com.

To post to this group, send email to simpleamqpc...@googlegroups.com.

Stephen Hsu

unread,
Nov 1, 2016, 5:29:48 AM11/1/16
to simpleamqpclient-users
Alan, Thanks for your kind help.

You are right. All the dependencies need to be compiled with x86_64-w64-mingw32-g++.
To unsubscribe from this group and stop receiving emails from it, send an email to simpleamqpclient-users+unsub...@googlegroups.com.
To post to this group, send email to simpleamqpc...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "simpleamqpclient-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to simpleamqpclient-users+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages