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

相關問題