【问题标题】:boost's regex won't compileboost的正则表达式不会编译
【发布时间】:2011-05-30 06:00:06
【问题描述】:

我在 Ubuntu 上使用 boost 1.45.0 和 Code::Blocks 作为我的 IDE,但我无法编译 basic_regex.hpp。我很确定我正确设置了 boost,因为我可以使用 boost::format 编译程序而不会出现任何错误。但是我遇到了这个烦人的错误,我不知道如何摆脱它。

引发错误的代码:

boost::regex e("\"http:\\\\/\\\\/localhostr.com\\\\/files\\\\/.+?\"");

编译器输出 (GCC):

obj/Debug/main.o
In function `boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::assign(char const*, char const*, unsigned int)'

/home/neal/Documents/boost_1_45_0/boost/regex/v4/basic_regex.hpp|379|
undefined reference to `boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int)'|

||=== Build finished: 1 errors, 0 warnings ===|

我在设置 boost 时错过了一步,还是应该降级到另一个版本的 boost?

【问题讨论】:

    标签: c++ regex gcc boost


    【解决方案1】:

    这看起来像是一个链接器错误。 boost::regex 不是仅标头库,因此您需要将 -lboost_regex 和正确的 -L/path/to/boost/lib 传递给链接器。

    【讨论】:

    • 感谢您的回复。它已经死了。 :)
    【解决方案2】:

    Boost::Regex 有一些代码位于单独的库 (libboost_regex.so) 中。要链接它,请将 -lboost_regex 添加到您正在使用的 GCC 命令行中。

    根据您的安装,可能是 libboost_regex-mt.so。在这种情况下,您需要在命令行上使用-lboost_regex-mt。 (MT 代表多线程。)

    【讨论】:

    • 这不是线程问题,但我会记住您的建议。 =)
    【解决方案3】:

    这是一个链接错误,而不是编译器错误。您需要明确链接到 Boost 的正则表达式库。

    g++ program.cpp -lboost_regex -L/path/to/boost/lib
    

    【讨论】:

      猜你喜欢
      • 2023-03-15
      • 1970-01-01
      • 2011-08-09
      • 2023-03-15
      • 1970-01-01
      • 2013-03-10
      • 1970-01-01
      • 1970-01-01
      • 2011-08-24
      相关资源
      最近更新 更多