【问题标题】:std::regex -- is there some lib that needs to be linked?std::regex - 是否有一些需要链接的库?
【发布时间】:2010-12-10 01:03:03
【问题描述】:

我收到以下代码的链接器错误:

#include <regex>

int main()
{
    std::regex rgx("ello");
    return 0;
}

test.o: In function `basic_regex':
/usr/lib/gcc/i586-redhat-linux/4.4.1/../../../../include/c++/4.4.1/tr1_impl/regex:769: undefined reference to `std::basic_regex<char, std::regex_traits<char> >::_M_compile()'
collect2: ld returned 1 exit status

【问题讨论】:

标签: c++ regex c++11


【解决方案1】:

来自gcc-4.4.1/include/c++/4.4.1/tr1_impl/regex

template <...>
class basic_regexp {
...
   private:
      /**
       * @brief Compiles a regular expression pattern into a NFA.
       * @todo Implement this function.
       */
      void _M_compile();

我猜它还没准备好。

更新:当前最前沿的 GCC (SVN @153546) 似乎还没有实现。

【讨论】:

  • 好吧,我想我也没有使用最前沿的 gcc。
  • 我必须说,对开发人员这样做非常虐待狂!至少应该在编译时打印一条警告说它没有实现,以避免开发人员浪费太多时间认为他们做错了什么。
  • 是的,确实很残酷。将一堆 C++ 代码从 MS Windows Visual Studio 10 移植到使用 std::regex 的 linux 上,它只在 GCC 4.4.7 上编译 peach 没有问题。所以标题告诉编译器一切都很好。但是一旦链接器步骤进入,它就会像大量“对`std::basic_regex ...的未定义引用...”一样爆炸
【解决方案2】:

您可以从以下位置获取实施状态: http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt01ch01.html#manual.intro.status.standard.tr1

要使用正则表达式,你可以安装 boost 库,他们的 tr1 已经包含了正则表达式。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-26
    • 2011-03-17
    • 2018-07-28
    • 1970-01-01
    • 2023-04-07
    相关资源
    最近更新 更多