0

我觉得我疯了,即时尝试编译一个简单的项目,以了解如何使用io_service,我无法编译它。尝试使用boost时链接错误:: asio

#include <iostream> 
#include <boost/asio.hpp> 
#include <boost/bind.hpp> 

class testClass 
{ 
    unsigned int other_number; 
    unsigned int main_number; 
    boost::asio::io_service& io_serv; 
public: 
    testClass(boost::asio::io_service& io) : other_number(0), io_serv(io), main_number(0){io_serv.post(boost::bind(&testClass::printNumbers, this));} 
    void changeNumber(int num) 
    { 
     io_serv.post(boost::bind(&testClass::doChangeNumber, this, num)); 
    } 

private: 
    void doChangeNumber(int num) 
    { 
     main_number = num; 
    } 
    void printNumbers() 
    { 
     std::cout<<"Main number is: "<<main_number<<" Other number is:"<<other_number<<std::endl; 
     other_number++; 
     Sleep(1000); 
     io_serv.post(boost::bind(&testClass::printNumbers, this)); 
    } 
}; 

void main() 
{ 
    boost::asio::io_service io_serv; 
    testClass tc(io_serv); 
    io_serv.run(); 
    int num = 0; 
    while (true) 
    { 
     tc.changeNumber(num++); 
     Sleep(2000); 
    } 
} 

我没有在 “项目性财产> C/C++ - >常规 - >附加包含目录” 添加一行:"C:\Program Files (x86)\boost_1_44_0";

而且我也加入“项目性财产>接头 - >附加库目录“的行:"C:\Program Files (x86)\boost_1_44_0\libs"; 但似乎没有任何工作... 我使用visual studio 2010 .. boost_1_44_0 \ libs中没有.lib文件...我从boost的网站下载了2次确保..

无论我做什么,我总是得到LINK : fatal error LNK1104: cannot open file 'libboost_system-vc100-mt-gd-1_44.lib'

回答

2

您可以在本地系统using bjam as described here(第5.2节)上构建Boost库。一旦你完成了,你应该很好 - 从Visual Studio命令提示符使用它,并确保你的项目有正确的LIB路径。

我相信,如果您使用Boost Pro Computing的安装程序,则预构建的库只会默认存在。

+0

我想你给了错误的链接,因为你给的链接没有5.2节.. – grich 2010-11-03 15:55:38

+1

@grich - 我的坏,现在修复 - 对不起 – 2010-11-03 15:56:31

+1

Tnx很多,工作 – grich 2010-11-03 16:41:46

相关问题