5

我正在尝试编译消息包(http://msgpack.org/)示例代码并不断收到这些我无法深入了解的错误:

g++ -o"MsgPack2" ./src/MsgPack2.o -lmsgpack -lmsgpackc

./src/MsgPack2.o: In function `main':
/mnt/eoh/workspace/MsgPack2/Debug/../src/MsgPack2.cpp:38:

未定义的msgpack::rpc::server::listen(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned short)' ./src/MsgPack2.o: In function循环引用:/usr/local/include/msgpack/rpc/loop.h:30:未定义 mp::wavy::loop::loop()' ./src/MsgPack2.o: In function的引用基数:/usr/local/include/msgpack/rpc/server.h:59:未定义的 msgpack::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: 未定义对 msgpack::rpc::server::~server()' ./src/MsgPack2.o: In function~base'的引用:/usr/local/include /msgpack/rpc/server.h:64:未定义对 msgpack::rpc::server::~server()' ./src/MsgPack2.o: In function myserver::dispatch(msgpack::rpc::request)' 的引用:/mnt/eoh/workspace/MsgPack2/Debug/../src/MsgPack2.cpp:14 : 对msgpack::rpc::request::method()' /mnt/eoh/workspace/MsgPack2/Debug/../src/MsgPack2.cpp:18: undefined reference tomsgpack::rpc::request::params()' 的 未定义引用./src/MsgPack2.o: 在函数msgpack::rpc::loop_util<msgpack::rpc::session_pool>::run(unsigned long)': /usr/local/include/msgpack/rpc/loop_util.h:34: undefined reference tomsgpack::rpc::session_pool::get_loop()' /usr/local/include/msgpack/rpc /loop_util.h:34:未定义的引用mp::wavy::loop::run(unsigned long)' ./src/MsgPack2.o: In functionvoid msgpack::rpc::request::call(int&, msgpack::type::nil&)': /usr/local/include/msgpack/rpc/request.h:119: 未定义对msgpack::rpc::request::is_sent() const' /usr/local/include/msgpack/rpc/request.h:122: undefined reference tomsgpack::rpc::的引用request::get_msgid() const' /usr/local/include/msgpack/rpc/request.h:125: undefined reference to msgpack::rpc::request::send_data(msgpack::sbuffer*)' ./src/MsgPack2.o: In functionvoid msgpack::rpc::request::call(msgpack::type::nil&, unsigned char& )': /usr/local/include/msgpack/rpc/request.h:119: 未定义对msgpack::rpc::request::is_sent() const' /usr/local/include/msgpack/rpc/request.h:122: undefined reference tomsgpack::rpc::request::get_msgid() 的引用 const' /usr/local/include/msgpack/rpc/request. h:125:对msgpack::rpc::request::send_data(msgpack::sbuffer*)' ./src/MsgPack2.o: In functionvoid msgpack::rpc::request::call、std::allocator 的未定义引用 >

(msgpack::type::nil&, std::basic_string, std::allocator >&)': /usr/local/include/msgpack/rpc/request.h:119: 未定义对msgpack::rpc::request::is_sent() const' /usr/local/include/msgpack/rpc/request.h:122: undefined reference tomsgpack::rpc::request的引用::get_msgid() const' /usr/local/include/msgpack/rpc/request.h:125: 未定义引用msgpack::rpc::request::send_data(msgpack::sbuffer*)' ./src/MsgPack2.o: In function__shared_count': /usr/include/c++/4.5/tr1/shared_ptr.h:121: 未定义引用 mp::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: 未定义引用`mp::wavy ::loop::~loop()' collect2: ld 返回 1 退出状态 make: * [MsgPack2] 错误 1

这是代码:

#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(&params);
                    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;
}

如果有人有任何想法,将不胜感激。

提前谢谢了,

4

1 回答 1

4

你需要-lmsgpack-rpc.

[旁注:80800不是一个有效的端口。]

于 2011-08-11T11:31:04.397 回答