I'm trying to compile the message pack (http://msgpack.org/) example code and keep getting these errors which I can't get to the bottom of:
g++ -o"MsgPack2" ./src/MsgPack2.o -lmsgpack -lmsgpackc
./src/MsgPack2.o: In function `main': /mnt/eoh/workspace/MsgPack2/Debug/../src/MsgPack2.cpp:38:
undefined reference to
msgpack::rpc::server::listen(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned short)' ./src/MsgPack2.o: In function
loop': /usr/local/include/msgpack/rpc/loop.h:30: undefined reference tomp::wavy::loop::loop()' ./src/MsgPack2.o: In function
base': /usr/local/include/msgpack/rpc/server.h:59: undefined reference tomsgpack::rpc::server::server(msgpack::rpc::loop)' /usr/local/include/msgpack/rpc/server.h:59: undefined reference to
msgpack::rpc::server::serve(msgpack::rpc::dispatcher*)' /usr/local/include/msgpack/rpc/server.h:59: undefined reference tomsgpack::rpc::server::~server()' ./src/MsgPack2.o: In function
~base': /usr/local/include/msgpack/rpc/server.h:64: undefined reference tomsgpack::rpc::server::~server()' ./src/MsgPack2.o: In function
myserver::dispatch(msgpack::rpc::request)': /mnt/eoh/workspace/MsgPack2/Debug/../src/MsgPack2.cpp:14: undefined reference tomsgpack::rpc::request::method()' /mnt/eoh/workspace/MsgPack2/Debug/../src/MsgPack2.cpp:18: undefined reference to
msgpack::rpc::request::params()' ./src/MsgPack2.o: In functionmsgpack::rpc::loop_util<msgpack::rpc::session_pool>::run(unsigned long)': /usr/local/include/msgpack/rpc/loop_util.h:34: undefined reference to
msgpack::rpc::session_pool::get_loop()' /usr/local/include/msgpack/rpc/loop_util.h:34: undefined reference tomp::wavy::loop::run(unsigned long)' ./src/MsgPack2.o: In function
void msgpack::rpc::request::call(int&, msgpack::type::nil&)': /usr/local/include/msgpack/rpc/request.h:119: undefined reference tomsgpack::rpc::request::is_sent() const' /usr/local/include/msgpack/rpc/request.h:122: undefined reference to
msgpack::rpc::request::get_msgid() const' /usr/local/include/msgpack/rpc/request.h:125: undefined reference tomsgpack::rpc::request::send_data(msgpack::sbuffer*)' ./src/MsgPack2.o: In function
void msgpack::rpc::request::call(msgpack::type::nil&, unsigned char&)': /usr/local/include/msgpack/rpc/request.h:119: undefined reference tomsgpack::rpc::request::is_sent() const' /usr/local/include/msgpack/rpc/request.h:122: undefined reference to
msgpack::rpc::request::get_msgid() const' /usr/local/include/msgpack/rpc/request.h:125: undefined reference tomsgpack::rpc::request::send_data(msgpack::sbuffer*)' ./src/MsgPack2.o: In function
void msgpack::rpc::request::call, std::allocator >(msgpack::type::nil&, std::basic_string, std::allocator >&)': /usr/local/include/msgpack/rpc/request.h:119: undefined reference to
msgpack::rpc::request::is_sent() const' /usr/local/include/msgpack/rpc/request.h:122: undefined reference to
msgpack::rpc::request::get_msgid() const' /usr/local/include/msgpack/rpc/request.h:125: undefined reference tomsgpack::rpc::request::send_data(msgpack::sbuffer*)' ./src/MsgPack2.o: In function
__shared_count': /usr/include/c++/4.5/tr1/shared_ptr.h:121: undefined reference tomp::wavy::loop::~loop()' ./src/MsgPack2.o: In function
std::tr1::_Sp_deleter::operator()(mp::wavy::loop*) const': /usr/include/c++/4.5/tr1/shared_ptr.h:99: undefined reference to `mp::wavy::loop::~loop()' collect2: ld returned 1 exit status make: * [MsgPack2] Error 1
And here is the code:
#include <msgpack/rpc/server.h>
class myserver : public msgpack::rpc::server::base {
public:
void add(msgpack::rpc::request req, int a1, int a2)
{
req.result(a1 + a2);
}
public:
void dispatch(msgpack::rpc::request req)
try {
std::string method;
req.method().convert(&method);
if(method == "add") {
msgpack::type::tuple<int, int> params;
req.params().convert(¶ms);
add(req, params.get<0>(), params.get<1>());
} else {
req.error(msgpack::rpc::NO_METHOD_ERROR);
}
} catch (msgpack::type_error& e) {
req.error(msgpack::rpc::ARGUMENT_ERROR);
return;
} catch (std::exception& e) {
req.error(std::string(e.what()));
return;
}
};
int main(void)
{
myserver svr;
svr.instance.listen("127.0.0.1", 80800);
svr.instance.run(4); // run 4 threads
return 0;
}
If anyone has any ideas, it would be greatly appreciated.
Many thanks in advance,
You need -lmsgpack-rpc
.
[Side note: 80800
is not a valid port.]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With