下图为已经安装好的库。
在这个程序中是可以成功调用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;
}