2010-02-16 54 views
7

我試圖在我的程序中使用boost正則表達式 問題是我得到這個錯誤... 唯一的安裝步驟我所做的就是補充: 「C:\ Program Files文件\提升\ boost_1_42」 進入附加包含目錄...致命錯誤LNK1104:無法打開文件'libboost_regex-vc90-mt-gd-1_42.lib'

我使用VS2008 ...

想實現這一點:

#include <iostream> 
#include <string> 
#include <boost/regex.hpp> 

using namespace std; 

int main() { 

    std::string s, sre; 
    boost::regex re; 
    boost::cmatch matches; 

    while(true) 
    { 
     cout << "Expression: "; 
     cin >> sre; 
     if (sre == "quit") 
     { 
     break; 
     } 

     cout << "String:  "; 
     cin >> s; 

     try 
     { 
     // Assignment and construction initialize the FSM used 
     // for regexp parsing 
     re = sre; 
     } 
     catch (boost::regex_error& e) 
     { 
     cout << sre << " is not a valid regular expression: \"" 
       << e.what() << "\"" << endl; 
     continue; 
     } 
     // if (boost::regex_match(s.begin(), s.end(), re)) 
     if (boost::regex_match(s.c_str(), matches, re)) 
     { 
     // matches[0] contains the original string. matches[n] 
     // contains a sub_match object for each matching 
     // subexpression 
     for (int i = 1; i < matches.size(); i++) 
     { 
      // sub_match::first and sub_match::second are iterators that 
      // refer to the first and one past the last chars of the 
      // matching subexpression 
      string match(matches[i].first, matches[i].second); 
      cout << "\tmatches[" << i << "] = " << match << endl; 
     } 
     } 
     else 
     { 
     cout << "The regexp \"" << re << "\" does not match \"" << s << "\"" << endl; 
     } 
    } 
} 

什麼似乎是問題?應該做什麼額外的設置?

回答

14

必須構建一些Boost庫;這是其中之一。這裏是你如何構建它們:

建立一個叫做boost_build.bat新文件,裏面放:

bjam toolset=msvc-9.0 variant=release threading=multi link=static define=_SECURE_SCL=0 define=_HAS_ITERATOR_DEBUGGING=0 
bjam toolset=msvc-9.0 variant=debug threading=multi link=static 

注9.0指的是VS 2008(10.0,爲2010年8.0 2005 7.1 2003年,6.0好吧,6.0)。一旦你做到了這一點:

  1. 提取build_boost.bat<boost_root>

  2. 轉到: <boost_root>\tools\jam 和運行build_dist.bat

  3. 複製<boost_root>\tools\jam\stage\bin.ntx86\bjam.exe<boost_root>

  4. 運行boost_build.bat

  5. 庫位於<boost_root>\stage\lib

注意,這是我自己的方法。我會如果有人用更簡單的方式發聲,或者某些鏈接來自Boost;似乎很難從Boost中找到正確的構建指令。

構建完成後,請確保讓編譯器知道VC目錄(庫路徑)中庫的位置;添加「<boost_root>\stage\lib」。


bjam定義,我有_SECURE_SCL=0_HAS_ITERATOR_DEBUGGING=0發佈。這會禁用發佈版本中的所有迭代器檢查,以提高速度。

+0

還是同樣的錯誤...... 1> LINK:致命錯誤LNK1104:無法打開文件 'libboost_regex-VC90-MT-GD-1_42.lib' 確實做到了爲u說... – kaycee

+0

確定它的工作原理.. 。添加到鏈接器「C:\ Program Files \ boost \ boost_1_42 \ stage \ lib \ libboost_regex-vc90-mt-gd-1_42.lib」 – kaycee

+0

'_HAS_ITERATOR_DEBUGGING'僅適用於Debug版本。不過,關於'_SECURE_SCL',您是否遇到過混合啓用庫的庫和禁用庫的問題? –

1

您是否安裝了Boost的多線程調試版本?如果沒有,請這樣做。否則,請檢查您的庫路徑(在項目首選項中),以便它包含錯誤消息中提及的文件的路徑。

2

在Windows上,獲取boost二進制庫的最簡單方法是運行installer from BoostPro consulting。請確保選擇您的Visual Studio版本,並在安裝過程中選中正規表達式庫的複選框。

+0

默認的源代碼安裝將很容易,如果他們沒有任意做愚蠢的事情做一個蝙蝠文件,你點擊,不做整個工作。爲什麼程序員不能製造出只是第一次工作的工具,並且遵循最少的驚愕原則。 BoostPro的安裝程序很好,我只是抱怨boost網站的zip文件下載。在我看來,他們應該放棄它們並將鏈接放到真正的安裝中。當然,BoostPro已經死亡或正在死亡,所以這個答案不再是最新的。 –

0

我對定義設置不太確定,但是我能夠使用MSVC 9進行構建。通過運行<boostroot>\bootstrap批處理文件,然後編輯<boostroot>\project-config.jam文件,如下所示。更改行:

using mvsc 

到:

using msvc : 9.0 : cl.exe 

然後運行.\b2 install和升壓頭文件和庫的建造和安裝c:\boost

相關問題