boost正则表达式中的链接器错误 [英] linker error in boost regex

查看:214
本文介绍了boost正则表达式中的链接器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想学习一些关于regex在boost lib和我尝试编译这个简单的示例代码:

I would like to learn something about regex in boost lib and i try compile this simple example code:

// regex_search example
#include <iostream>
#include <string>
#include <boost/regex.hpp>

int main ()
{
  std::string s ("this subject has a submarine as a subsequence");
  boost::smatch m;
  boost::regex e ("\\b(sub)([^ ]*)");   // matches words beginning by "sub"

  std::cout << "Target sequence: " << s << std::endl;
  std::cout << "Regular expression: /\\b(sub)([^ ]*)/" << std::endl;
  std::cout << "The following matches and submatches were found:" << std::endl;

  while (boost::regex_search (s,m,e)) {
    for (auto x:m) std::cout << x << " ";
    std::cout << std::endl;
    s = m.suffix().str();
  }

  return 0;
}

我使用: g ++ -std = c ++ 0x -I / usr / lib / boost / include -L / usr / lib / boost / lib -lboost_regex test_regex.cpp

显示我:

/tmp/ccjni2je.o: In function `boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::assign(char const*, char const*, unsigned int)':
test_regex.cpp:(.text._ZN5boost11basic_regexIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE6assignEPKcS7_j[boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::assign(char const*, char const*, unsigned int)]+0x22): undefined reference to `boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int)'
/tmp/ccjni2je.o: In function `bool boost::regex_search<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, char, boost::regex_traits<char, boost::cpp_regex_

任何人都可以帮助我?

推荐答案

/ p>

Three things:


  1. Boost.Regex库可能称为 libboost_regex -mt

  2. 除非你知道Boost lib是用C ++ 11支持编译的,否则应该删除
    -std = c ++ 0x 选项。

  3. 您应始终将LIBS放在末尾,因为GNU ld 对象文件和LIBS出现在命令行中。

  1. The Boost.Regex library is likely called libboost_regex-mt.
  2. Unless you know that a Boost lib was compiled with C++11 support, you should remove the
    -std=c++0x option.
  3. You should always place LIBS at the end because GNU ld resolves symbols in the order that object files and LIBS appear in the command line.

尝试:


g++ -I /usr/lib/boost/include -L /usr/lib/boost/lib test_regex.cpp -lboost_regex-mt

这篇关于boost正则表达式中的链接器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆