C++ MsgPack:链接器错误

发布于 2024-11-29 02:03:45 字数 5472 浏览 1 评论 0原文

我正在尝试编译消息包(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:
> 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 to
> `mp::wavy::loop::loop()'
>     ./src/MsgPack2.o: In function `base':
>     /usr/local/include/msgpack/rpc/server.h:59: undefined reference to
> `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: undefined reference to
> `msgpack::rpc::server::~server()'
>     ./src/MsgPack2.o: In function `~base':
>     /usr/local/include/msgpack/rpc/server.h:64: undefined reference to
> `msgpack::rpc::server::~server()'
>     ./src/MsgPack2.o: In function
> `myserver::dispatch(msgpack::rpc::request)':
>     /mnt/eoh/workspace/MsgPack2/Debug/../src/MsgPack2.cpp:14:
> undefined reference to `msgpack::rpc::request::method()'
>     /mnt/eoh/workspace/MsgPack2/Debug/../src/MsgPack2.cpp:18:
> undefined reference to `msgpack::rpc::request::params()'
>     ./src/MsgPack2.o: In function
> `msgpack::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
> to `mp::wavy::loop::run(unsigned long)'
>     ./src/MsgPack2.o: In function `void
> msgpack::rpc::request::call<int, msgpack::type::nil>(int&,
> msgpack::type::nil&)':
>     /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
> to `msgpack::rpc::request::send_data(msgpack::sbuffer*)'
>     ./src/MsgPack2.o: In function `void
> msgpack::rpc::request::call<msgpack::type::nil, unsigned
> char>(msgpack::type::nil&, unsigned char&)':
>     /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
> to `msgpack::rpc::request::send_data(msgpack::sbuffer*)'
>     ./src/MsgPack2.o: In function `void
> msgpack::rpc::request::call<msgpack::type::nil,
> std::basic_string<char, std::char_traits<char>, std::allocator<char> >
> >(msgpack::type::nil&, std::basic_string<char, std::char_traits<char>,
> std::allocator<char> >&)':
>     /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
> to `msgpack::rpc::request::send_data(msgpack::sbuffer*)'
>     ./src/MsgPack2.o: In function `__shared_count<mp::wavy::loop*>':
>     /usr/include/c++/4.5/tr1/shared_ptr.h:121: undefined reference to
> `mp::wavy::loop::~loop()'
>     ./src/MsgPack2.o: In function
> `std::tr1::_Sp_deleter<mp::wavy::loop>::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

这是代码:

#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;
}

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

预先非常感谢,

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 to
> `mp::wavy::loop::loop()'
>     ./src/MsgPack2.o: In function `base':
>     /usr/local/include/msgpack/rpc/server.h:59: undefined reference to
> `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: undefined reference to
> `msgpack::rpc::server::~server()'
>     ./src/MsgPack2.o: In function `~base':
>     /usr/local/include/msgpack/rpc/server.h:64: undefined reference to
> `msgpack::rpc::server::~server()'
>     ./src/MsgPack2.o: In function
> `myserver::dispatch(msgpack::rpc::request)':
>     /mnt/eoh/workspace/MsgPack2/Debug/../src/MsgPack2.cpp:14:
> undefined reference to `msgpack::rpc::request::method()'
>     /mnt/eoh/workspace/MsgPack2/Debug/../src/MsgPack2.cpp:18:
> undefined reference to `msgpack::rpc::request::params()'
>     ./src/MsgPack2.o: In function
> `msgpack::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
> to `mp::wavy::loop::run(unsigned long)'
>     ./src/MsgPack2.o: In function `void
> msgpack::rpc::request::call<int, msgpack::type::nil>(int&,
> msgpack::type::nil&)':
>     /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
> to `msgpack::rpc::request::send_data(msgpack::sbuffer*)'
>     ./src/MsgPack2.o: In function `void
> msgpack::rpc::request::call<msgpack::type::nil, unsigned
> char>(msgpack::type::nil&, unsigned char&)':
>     /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
> to `msgpack::rpc::request::send_data(msgpack::sbuffer*)'
>     ./src/MsgPack2.o: In function `void
> msgpack::rpc::request::call<msgpack::type::nil,
> std::basic_string<char, std::char_traits<char>, std::allocator<char> >
> >(msgpack::type::nil&, std::basic_string<char, std::char_traits<char>,
> std::allocator<char> >&)':
>     /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
> to `msgpack::rpc::request::send_data(msgpack::sbuffer*)'
>     ./src/MsgPack2.o: In function `__shared_count<mp::wavy::loop*>':
>     /usr/include/c++/4.5/tr1/shared_ptr.h:121: undefined reference to
> `mp::wavy::loop::~loop()'
>     ./src/MsgPack2.o: In function
> `std::tr1::_Sp_deleter<mp::wavy::loop>::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,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

微凉 2024-12-06 02:03:45

您需要-lmsgpack-rpc

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

You need -lmsgpack-rpc.

[Side note: 80800 is not a valid port.]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文