【发布时间】:2014-12-06 02:44:01
【问题描述】:
早上好!
我对 C++11 中的正则表达式有疑问。 我有 Ubuntu Light 14.04 和这个版本的编译器:
g++ (Ubuntu 4.8.2-19ubuntu1) 4.8.2
Copyright (C) 2013 Free Software Foundation, Inc.
我今天使用这三个命令安装了 boost。
sudo apt-get install libboost-all-dev
sudo apt-get install aptitude
aptitude search boost
当我编译这个简单的程序时:
#include <iostream>
#include <string>
#include <boost/regex.hpp>
using namespace boost;
using namespace std;
int main()
{
string text;
regex pattern( "\\w* to \\w*" );
return 0;
}
使用这个命令:
g++ main.cpp
编译器返回:
/tmp/ccOdFz7f.o: In function `boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::assign(char const*, char const*, unsigned int)':
main.cpp:(.text._ZN5boost11basic_regexIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE6assignEPKcS7_j[_ZN5boost11basic_regexIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE6assignEPKcS7_j]+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)'
collect2: error: ld returned 1 exit status
我读到了这个话题:linker error in boost regex 并使用了这个命令:
g++ -I /usr/lib/boost/include -L /usr/lib/boost/lib main.cpp -lboost_regex-mt
但编译器返回:
/usr/bin/ld: cannot find -lboost_regex-mt
collect2: error: ld returned 1 exit status
我也没有 /usr/lib/boost 目录!!!
我应该在这个程序中或在 Ubuntu 中做些什么来使用 boost 中的正则表达式?
【问题讨论】:
标签: c++ regex c++11 boost linkage