"Undefined reference to" Linking errors when trying to build with headers (QPID/Proton C++)

  amqp, c++, qpid

I’m a C++ neophyte and I am totally in over my head, but I’m trying anyway!

http://qpid.apache.org/releases/qpid-proton-0.33.0/proton/cpp/examples/simple_recv.cpp.html

I am trying to incorporate the above into an existing project and struggling badly. In order to be able to use various instances of the QPID Proton sender/receiver, I need to include their class files. The example is a pure cpp and includes no header file.

In order to include a receiver (consumer) class, I need to write a header file. And it’s all falling apart on compile.

Here’s a really simple example. I’m trying to start out and just go more or less line by line with the receiver example. So, here’s my cpp:

#include "ProtonConsumer.h"
ProtonConsumer::ProtonConsumer(const std::string &s) :
    url(s) {};

Here’s the header:

class ProtonConsumer : public proton::messaging_handler {
  private:
    std::string url;
    proton::receiver receiver;

  public:
    // constructor
    ProtonConsumer(const std::string &s);
};

In my main, I’m trying to simply use an instance of the ProtonConsumer:

#include "../Network/ProtonConsumer.h"
    ProtonConsumer pProtonConsumer(strProtonURI);

When I try to build (cmake), I get all kinds of "undefined reference to" and other errors:

[main] Building folder: srt-game-server 
[build] Starting build
[proc] Executing command: /usr/bin/cmake --build /home/thoraxe/Red_Hat/openshift/srt-game-server/build --config Debug --target all -- -j 10
[build] Scanning dependencies of target srt-game-server
[build] [  2%] Building CXX object CMakeFiles/srt-game-server.dir/src/Application/main.cpp.o
[build] [  5%] Building CXX object CMakeFiles/srt-game-server.dir/src/Network/ProtonConsumer.cpp.o
[build] [  7%] Linking CXX executable srt-game-server
[build] /usr/bin/ld: CMakeFiles/srt-game-server.dir/src/Application/main.cpp.o:(.data.rel.ro._ZTV14ProtonConsumer[_ZTV14ProtonConsumer]+0x20): undefined reference to `proton::messaging_handler::on_container_start(proton::container&)'
[build] /usr/bin/ld: CMakeFiles/srt-game-server.dir/src/Application/main.cpp.o:(.data.rel.ro._ZTV14ProtonConsumer[_ZTV14ProtonConsumer]+0x28): undefined reference to `proton::messaging_handler::on_container_stop(proton::container&)'
[build] /usr/bin/ld: CMakeFiles/srt-game-server.dir/src/Application/main.cpp.o:(.data.rel.ro._ZTV14ProtonConsumer[_ZTV14ProtonConsumer]+0x30): undefined reference to `proton::messaging_handler::on_message(proton::delivery&, proton::message&)'
[build] /usr/bin/ld: CMakeFiles/srt-game-server.dir/src/Application/main.cpp.o:(.data.rel.ro._ZTV14ProtonConsumer[_ZTV14ProtonConsumer]+0x38): undefined reference to `proton::messaging_handler::on_sendable(proton::sender&)'
[build] /usr/bin/ld: CMakeFiles/srt-game-server.dir/src/Application/main.cpp.o:(.data.rel.ro._ZTV14ProtonConsumer[_ZTV14ProtonConsumer]+0x40): undefined reference to `proton::messaging_handler::on_transport_open(proton::transport&)'
[build] /usr/bin/ld: CMakeFiles/srt-game-server.dir/src/Application/main.cpp.o:(.data.rel.ro._ZTV14ProtonConsumer[_ZTV14ProtonConsumer]+0x48): undefined reference to `proton::messaging_handler::on_transport_close(proton::transport&)'
[build] /usr/bin/ld: CMakeFiles/srt-game-server.dir/src/Application/main.cpp.o:(.data.rel.ro._ZTV14ProtonConsumer[_ZTV14ProtonConsumer]+0x50): undefined reference to `proton::messaging_handler::on_transport_error(proton::transport&)'
[build] /usr/bin/ld: CMakeFiles/srt-game-server.dir/src/Application/main.cpp.o:(.data.rel.ro._ZTV14ProtonConsumer[_ZTV14ProtonConsumer]+0x58): undefined reference to `proton::messaging_handler::on_connection_open(proton::connection&)'
[build] /usr/bin/ld: CMakeFiles/srt-game-server.dir/src/Application/main.cpp.o:(.data.rel.ro._ZTV14ProtonConsumer[_ZTV14ProtonConsumer]+0x60): undefined reference to `proton::messaging_handler::on_connection_close(proton::connection&)'
[build] /usr/bin/ld: CMakeFiles/srt-game-server.dir/src/Application/main.cpp.o:(.data.rel.ro._ZTV14ProtonConsumer[_ZTV14ProtonConsumer]+0x68): undefined reference to `proton::messaging_handler::on_connection_error(proton::connection&)'
[build] /usr/bin/ld: CMakeFiles/srt-game-server.dir/src/Application/main.cpp.o:(.data.rel.ro._ZTV14ProtonConsumer[_ZTV14ProtonConsumer]+0x70): undefined reference to `proton::messaging_handler::on_session_open(proton::session&)'
[build] /usr/bin/ld: CMakeFiles/srt-game-server.dir/src/Application/main.cpp.o:(.data.rel.ro._ZTV14ProtonConsumer[_ZTV14ProtonConsumer]+0x78): undefined reference to `proton::messaging_handler::on_session_close(proton::session&)'
[build] /usr/bin/ld: CMakeFiles/srt-game-server.dir/src/Application/main.cpp.o:(.data.rel.ro._ZTV14ProtonConsumer[_ZTV14ProtonConsumer]+0x80): undefined reference to `proton::messaging_handler::on_session_error(proton::session&)'
[build] /usr/bin/ld: CMakeFiles/srt-game-server.dir/src/Application/main.cpp.o:(.data.rel.ro._ZTV14ProtonConsumer[_ZTV14ProtonConsumer]+0x88): undefined reference to `proton::messaging_handler::on_receiver_open(proton::receiver&)'
[build] /usr/bin/ld: CMakeFiles/srt-game-server.dir/src/Application/main.cpp.o:(.data.rel.ro._ZTV14ProtonConsumer[_ZTV14ProtonConsumer]+0x90): undefined reference to `proton::messaging_handler::on_receiver_detach(proton::receiver&)'
[build] /usr/bin/ld: CMakeFiles/srt-game-server.dir/src/Application/main.cpp.o:(.data.rel.ro._ZTV14ProtonConsumer[_ZTV14ProtonConsumer]+0x98): undefined reference to `proton::messaging_handler::on_receiver_close(proton::receiver&)'
[build] /usr/bin/ld: CMakeFiles/srt-game-server.dir/src/Application/main.cpp.o:(.data.rel.ro._ZTV14ProtonConsumer[_ZTV14ProtonConsumer]+0xa0): undefined reference to `proton::messaging_handler::on_receiver_error(proton::receiver&)'
[build] /usr/bin/ld: CMakeFiles/srt-game-server.dir/src/Application/main.cpp.o:(.data.rel.ro._ZTV14ProtonConsumer[_ZTV14ProtonConsumer]+0xa8): undefined reference to `proton::messaging_handler::on_sender_open(proton::sender&)'
[build] /usr/bin/ld: CMakeFiles/srt-game-server.dir/src/Application/main.cpp.o:(.data.rel.ro._ZTV14ProtonConsumer[_ZTV14ProtonConsumer]+0xb0): undefined reference to `proton::messaging_handler::on_sender_detach(proton::sender&)'
[build] /usr/bin/ld: CMakeFiles/srt-game-server.dir/src/Application/main.cpp.o:(.data.rel.ro._ZTV14ProtonConsumer[_ZTV14ProtonConsumer]+0xb8): undefined reference to `proton::messaging_handler::on_sender_close(proton::sender&)'
[build] /usr/bin/ld: CMakeFiles/srt-game-server.dir/src/Application/main.cpp.o:(.data.rel.ro._ZTV14ProtonConsumer[_ZTV14ProtonConsumer]+0xc0): undefined reference to `proton::messaging_handler::on_sender_error(proton::sender&)'
[build] /usr/bin/ld: CMakeFiles/srt-game-server.dir/src/Application/main.cpp.o:(.data.rel.ro._ZTV14ProtonConsumer[_ZTV14ProtonConsumer]+0xc8): undefined reference to `proton::messaging_handler::on_tracker_accept(proton::tracker&)'
[build] /usr/bin/ld: CMakeFiles/srt-game-server.dir/src/Application/main.cpp.o:(.data.rel.ro._ZTV14ProtonConsumer[_ZTV14ProtonConsumer]+0xd0): undefined reference to `proton::messaging_handler::on_tracker_reject(proton::tracker&)'
[build] /usr/bin/ld: CMakeFiles/srt-game-server.dir/src/Application/main.cpp.o:(.data.rel.ro._ZTV14ProtonConsumer[_ZTV14ProtonConsumer]+0xd8): undefined reference to `proton::messaging_handler::on_tracker_release(proton::tracker&)'
[build] /usr/bin/ld: CMakeFiles/srt-game-server.dir/src/Application/main.cpp.o:(.data.rel.ro._ZTV14ProtonConsumer[_ZTV14ProtonConsumer]+0xe0): undefined reference to `proton::messaging_handler::on_tracker_settle(proton::tracker&)'
[build] /usr/bin/ld: CMakeFiles/srt-game-server.dir/src/Application/main.cpp.o:(.data.rel.ro._ZTV14ProtonConsumer[_ZTV14ProtonConsumer]+0xe8): undefined reference to `proton::messaging_handler::on_delivery_settle(proton::delivery&)'
[build] /usr/bin/ld: CMakeFiles/srt-game-server.dir/src/Application/main.cpp.o:(.data.rel.ro._ZTV14ProtonConsumer[_ZTV14ProtonConsumer]+0xf0): undefined reference to `proton::messaging_handler::on_sender_drain_start(proton::sender&)'
[build] /usr/bin/ld: CMakeFiles/srt-game-server.dir/src/Application/main.cpp.o:(.data.rel.ro._ZTV14ProtonConsumer[_ZTV14ProtonConsumer]+0xf8): undefined reference to `proton::messaging_handler::on_receiver_drain_finish(proton::receiver&)'
[build] /usr/bin/ld: CMakeFiles/srt-game-server.dir/src/Application/main.cpp.o:(.data.rel.ro._ZTV14ProtonConsumer[_ZTV14ProtonConsumer]+0x100): undefined reference to `proton::messaging_handler::on_connection_wake(proton::connection&)'
[build] /usr/bin/ld: CMakeFiles/srt-game-server.dir/src/Application/main.cpp.o:(.data.rel.ro._ZTV14ProtonConsumer[_ZTV14ProtonConsumer]+0x108): undefined reference to `proton::messaging_handler::on_error(proton::error_condition const&)'
[build] /usr/bin/ld: CMakeFiles/srt-game-server.dir/src/Application/main.cpp.o:(.data.rel.ro._ZTI14ProtonConsumer[_ZTI14ProtonConsumer]+0x10): undefined reference to `typeinfo for proton::messaging_handler'
[build] /usr/bin/ld: CMakeFiles/srt-game-server.dir/src/Application/main.cpp.o: in function `ProtonConsumer::~ProtonConsumer()':
[build] /home/thoraxe/Red_Hat/openshift/srt-game-server/src/Application/../Network/ProtonConsumer.h:19: undefined reference to `proton::receiver::~receiver()'
[build] /usr/bin/ld: /home/thoraxe/Red_Hat/openshift/srt-game-server/src/Application/../Network/ProtonConsumer.h:19: undefined reference to `proton::messaging_handler::~messaging_handler()'
[build] /usr/bin/ld: CMakeFiles/srt-game-server.dir/src/Network/ProtonConsumer.cpp.o: in function `ProtonConsumer::ProtonConsumer(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
[build] /home/thoraxe/Red_Hat/openshift/srt-game-server/src/Network/ProtonConsumer.cpp:19: undefined reference to `proton::messaging_handler::messaging_handler()'
[build] /usr/bin/ld: /home/thoraxe/Red_Hat/openshift/srt-game-server/src/Network/ProtonConsumer.cpp:19: undefined reference to `proton::messaging_handler::~messaging_handler()'
[build] /usr/bin/ld: CMakeFiles/srt-game-server.dir/src/Network/ProtonConsumer.cpp.o: in function `proton::endpoint::endpoint()':
[build] /usr/include/proton/endpoint.hpp:67: undefined reference to `vtable for proton::endpoint'
[build] /usr/bin/ld: CMakeFiles/srt-game-server.dir/src/Network/ProtonConsumer.cpp.o: in function `proton::link::link()':
[build] /usr/include/proton/link.hpp:49: undefined reference to `vtable for proton::link'
[build] /usr/bin/ld: CMakeFiles/srt-game-server.dir/src/Network/ProtonConsumer.cpp.o: in function `proton::receiver::receiver()':
[build] /usr/include/proton/receiver.hpp:48: undefined reference to `vtable for proton::receiver'
[build] /usr/bin/ld: CMakeFiles/srt-game-server.dir/src/Network/ProtonConsumer.cpp.o: in function `proton::internal::pn_ptr<pn_link_t>::pn_ptr(pn_link_t*)':
[build] /usr/include/proton/internal/object.hpp:48: undefined reference to `proton::internal::pn_ptr_base::incref(void*)'
[build] /usr/bin/ld: CMakeFiles/srt-game-server.dir/src/Network/ProtonConsumer.cpp.o: in function `proton::internal::pn_ptr<pn_link_t>::~pn_ptr()':
[build] /usr/include/proton/internal/object.hpp:55: undefined reference to `proton::internal::pn_ptr_base::decref(void*)'
[build] /usr/bin/ld: CMakeFiles/srt-game-server.dir/src/Network/ProtonConsumer.cpp.o: in function `proton::internal::pn_ptr<pn_link_t>::pn_ptr(proton::internal::pn_ptr<pn_link_t> const&)':
[build] /usr/include/proton/internal/object.hpp:49: undefined reference to `proton::internal::pn_ptr_base::incref(void*)'
[build] collect2: error: ld returned 1 exit status
[build] gmake[2]: *** [CMakeFiles/srt-game-server.dir/build.make:682: srt-game-server] Error 1
[build] gmake[1]: *** [CMakeFiles/Makefile2:95: CMakeFiles/srt-game-server.dir/all] Error 2
[build] gmake: *** [Makefile:103: all] Error 2
[build] Build finished with exit code 2

I have dug around in GitHub and found various other examples where headers are used, for example here. Many of the undefined reference errors I’m getting in my code are functions declared in the header file of this reference example. I believe that the ~ProtonConsumer error is related to having a destructor, or something?

I’m super totally lost and not quite sure where to go from here. It looks like I might have to define all of the _ZTV14ProtonConsumer undefined references in my header and my class, but I’m not sure about the other things. The code example I referenced did not declare all of the functions. It’s not entirely clear from the messaging handler documentation which functions might be required to be declared, or not.

After considerable digging, the only thing I found that might be related was this post, but it doesn’t seem related after inspection.

Source: Windows Questions C++

LEAVE A COMMENT