【问题标题】:Boost.Regex linkage error LUbuntu 14.04 g++ 4.8.2Boost.Regex 链接错误 LUbuntu 14.04 g++ 4.8.2
【发布时间】: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


    【解决方案1】:

    链接器找不到指定的文件。 使用-lboost_regex 链接库。

    要找到已安装的正则表达式库,请调用locate libboost_regex,如下所示:

    $ locate libboost_regex
    /usr/lib/x86_64-linux-gnu/libboost_regex.a
    /usr/lib/x86_64-linux-gnu/libboost_regex.so
    /usr/lib/x86_64-linux-gnu/libboost_regex.so.1.54.0
    

    在我的例子中,它安装在/usr/lib/x86_64-linux-gnu 目录中

    【讨论】:

      猜你喜欢
      • 2012-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多