我需要在我的程序中使用正则表达式匹配。我决定使用boost库,但是在尝试编译时我收到了奇怪的失败。怎么了?? 有我的代码:
...
#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 :: allocator&gt; :: ~reg_expression()'...
答案 0 :(得分:1)
添加:
-lboost_regex
到您的编译器选项。