【问题标题】:Compile std::regex_iterator with gcc用 gcc 编译 std::regex_iterator
【发布时间】: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 的哪个版本? &lt;regex&gt; 实际上并没有在 4.6.2 之前实现。另外,为什么不改用std::cregex_iterator?
  • 您考虑过使用 boost 正则表达式库吗? boost::regex 和 boost::xpressive 都是功能齐全的。
  • 我知道,我用过这个工作人员,但现在我不能......
  • 这可能对某人有所帮助:如果您认为自己在 gcc 4.7.1 中实现了正则表达式,请不要上当。仔细查看 regex.h 的内容,您会发现它充满了 TODO 条目和未实现的函数。

标签: c++ regex linker g++ c++11


【解决方案1】:

The GNU C++ standard library supports &lt;regex&gt;,但not until version 4.9.0。 (标头存在于早期版本中,但无法使用。)

据我所知,其他编译器不支持它。

如果您使用较旧的 GCC,则可以使用 different library。

【讨论】:

  • MSVC 和 Clang 都支持 。实际上,正则表达式几乎是 C++11 中 GCC 落后于其他编译器的唯一部分。
猜你喜欢
  • 2020-05-18
  • 2016-11-13
  • 1970-01-01
  • 2017-03-09
  • 2017-06-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多