boost库的调用ld问题

1152阅读 0评论2012-10-12 lubing521
分类:C/C++

     最近编译并安装了boost库,想试试它的性能如何?结果在小试一番还是没成功调用。先把现象记录下来
下图为已经安装好的库。
在这个程序中是可以成功调用boost里面的smart_prt
#include
#include
#include
#include

class A
{
public:
    A(std::string s){a=s;}
    std::string a;
    void print(){std::cout<
    
};

int main()
{
    boost::shared_ptr p1(new A("2345"));
    boost::shared_ptr p2(new A("dfgds"));
    std::vector< boost::shared_ptr > m;
    std::vector< boost::shared_ptr >::iterator it;

    m.push_back(p1);
    m.push_back(p2);
    for (it=m.begin();it!=m.end();it++)
    {
        (*it)->print();
    }
return 1;
}

下图运行结果
而下面的程序在ld的时候就出问题了


#include
#include
#include
#include
#include
#include
#include

int main(int argc, char* argv[]){
using namespace boost::asio;
// 所有asio类都需要io_service对象
io_service iosev;
ip::tcp::acceptor acceptor(iosev,
ip::tcp::endpoint(ip::tcp::v4(), 1000));
for(;;)
{
// socket对象
ip::tcp::socket socket(iosev);
// 等待直到客户端连接进来
acceptor.accept(socket);
// 显示连接进来的客户端
std::cout << socket.remote_endpoint().address() << std::endl;
// 向客户端发送hello world!
boost::system::error_code ec;
socket.write_some(buffer("hello world!"), ec);

// 如果出错,打印出错信息
if(ec)
{
std::cout <<
boost::system::system_error(ec).what() << std::endl;
break;
}
// 与当前客户交互完成后循环继续等待下一客户连接
}
return 0;
}

上一篇:dns与wins的区别
下一篇:boost库的调用ld问题[已解]