2012-03-24 64 views
0

我需要在我的程序中使用正則表達式匹配。我決定使用boost庫,但在嘗試編譯時遇到奇怪的失敗。哪裏不對?? 有我的代碼:Boost :: regex_match失敗

... 
#include <boost/regex.hpp> 
... 
using namespace boost; 
... 
map <string, double>::iterator container::find (string toFind) 
{ 
    iterator it; 
    for (it=mainMap.begin(); it!=mainMap.end(); it++) 
    { 
     regex e ((*it).first);   //this line works correct 
     if (regex_match (toFind, e)) 
      return it; 
    } 
    return it; 
} 
... 

錯誤消息是大的發佈,有它的開始:

TMP/cczkfDcy.o(.gnu.linkonce.t._ZN5boost11basic_regexIcNS_12regex_traitsIcEESaIcEED1Ev + 0×11): 在功能boost::basic_regex<char, boost::regex_traits<char>, std::allocator<char> >::~basic_regex()': : undefined reference to 的boost :: reg_expression, 的std ::分配器> ::〜reg_expression()」 ......

回答

1

地址:

-lboost_regex 

到您的編譯器選項。

+0

謝謝))它的工作原理! – 2012-03-24 11:43:49

+1

你可以upvote並接受有用的答案 - http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work :) – 2012-03-24 13:07:31