g++编译boost::asio时错误(boost service)

source:http://blog.sina.com.cn/s/blog_6e4643130100x0tj.html


提前已经编译好了boost库经测试没有问题。
代码:
  service.cpp                                                                        
#include <iostream>
#include <boost/asio.hpp>
using namespace std;
using boost::asio::ip::tcp;

int main ()
{
    try
    {
    //
        boost::asio::io_service ioservice;
        tcp::acceptoraccept(ioservice,tcp::endpoint(tcp::v4(),6688));
        while(true)
        {
            tcp::socket sock(ioservice);
            accept.accept(sock);
            cout<<sock.remote_endpoint().address()<<endl;
            sock.write_some(boost::asio::buffer("hello pig"));
        }
    }
    catch(exception&e)
    {
        cerr<<e.what()<<endl;
    }

    return 0;
}

编译:
g++ service.cpp

错误:
/tmp/ccSU1pc4.o: In function`__static_initialization_and_destruction_0(int, int)':
service.cpp:(.text+0x22f): undefined reference to`boost::system::generic_category()'
service.cpp:(.text+0x239): undefined reference to`boost::system::generic_category()'
service.cpp:(.text+0x243): undefined reference to`boost::system::system_category()'
/tmp/ccSU1pc4.o: In function`boost::system::error_code::error_code()':
service.cpp:(.text._ZN5boost6system10error_codeC2Ev[_ZN5boost6system10error_codeC5Ev]+0x10):undefined reference to `boost::system::system_category()'
/tmp/ccSU1pc4.o: In function`boost::asio::error::get_system_category()':
service.cpp:(.text._ZN5boost4asio5error19get _system_categoryEv[boost::asio::error::get_system_category()]+0x7):undefined reference to `boost::system::system_category()'
/tmp/ccSU1pc4.o: In function`boost::asio::detail::posix_tss_ptr_create(unsignedint&)':
service.cpp:(.text._ZN5boost4asio6detail20po six_tss_ptr_createERj[boost::asio::detail::posix_tss_ptr_create(unsignedint&)]+0x15): undefined reference to`pthread_key_create'
/tmp/ccSU1pc4.o: In function`boost::asio::detail::posix_tss_ptr<boost::asio::detail::call_stack<boost::asio::detail::task_io_service>::context>::~posix_tss_ptr()':
service.cpp:(.text._ZN5boost4asio6detail13po six_tss_ptrINS1_10call_stackINS1_15task_io_serviceEE7contextEED2Ev[_ZN5boost4asio6detail13po six_tss_ptrINS1_10call_stackINS1_15task_io_serviceEE7contextEED5Ev]+0xf):undefined reference to `pthread_key_delete'
/tmp/ccSU1pc4.o: In function`boost::asio::detail::posix_tss_ptr<boost::asio::detail::call_stack<boost::asio::detail::strand_service::strand_impl>::context>::~posix_tss_ptr()':
service.cpp:(.text._ZN5boost4asio6detail13po six_tss_ptrINS1_10call_stackINS1_14strand_service11strand_implEE7contextEED2Ev[_ZN5boost4asio6detail13po six_tss_ptrINS1_10call_stackINS1_14strand_service11strand_implEE7contextEED5Ev]+0xf):undefined reference to `pthread_key_delete'
collect2: ld 返回 1

重新编译:
g++ -o service service.cpp -L -lboost_thread -lboost_system



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值