【发布时间】:2012-01-23 14:44:03
【问题描述】:
我可以使用 g++ -c test.cpp -std=c++0x 创建 .o 文件,但无法链接,出现下一个错误:
test.cpp:(.text+0xe5): undefined reference to `std::regex_iterator<char const*, char, std::regex_traits<char> >::regex_iterator(char const*, char const*, std::basic_regex<char, std::regex_traits<char> > const&, std::bitset<11u>)'
test.cpp:(.text+0xf1): undefined reference to `std::regex_iterator<char const*, char, std::regex_traits<char> >::regex_iterator()'
代码:
#include <regex>
#include <iostream>
#include <string.h>
typedef std::regex_iterator<const char *> Myiter;
int main()
{
const char *pat = "axayaz";
Myiter::regex_type rx("a");
Myiter next(pat, pat + strlen(pat), rx);
Myiter end;
return (0);
}
【问题讨论】:
-
GCC 的哪个版本?
<regex>实际上并没有在 4.6.2 之前实现。另外,为什么不改用std::cregex_iterator? -
您考虑过使用 boost 正则表达式库吗? boost::regex 和 boost::xpressive 都是功能齐全的。
-
我知道,我用过这个工作人员,但现在我不能......
-
这可能对某人有所帮助:如果您认为自己在 gcc 4.7.1 中实现了正则表达式,请不要上当。仔细查看 regex.h 的内容,您会发现它充满了 TODO 条目和未实现的函数。
标签: c++ regex linker g++ c++11