libstdc ++ - 由于tr1 / regex而编译失败

时间:2011-01-17 22:21:15

标签: c++ regex linux g++

我在OpenSUSE 11.3上安装了这些软件包:

i | libstdc++45       | Standard shared library for C++                 | package
i | libstdc++45-devel | Contains files and libraries for development    | package

但是当我试图编译这个C ++代码时:

#include <cstdio>
#include <tr1/regex>

using namespace std;

int main() {
    int test[2];
    const tr1::regex pattern(".*");

    test[0] = 1;

    if (tr1::regex_match("anything", pattern) == false) {
        printf("Pattern does not match.\n");
    }
    return 0;
}
使用

g++ -pedantic -g -O1 -o ./main.o ./main.cpp

输出此错误:

/tmp/cc0g3GUE.o: In function `basic_regex':
/usr/include/c++/4.5/tr1_impl/regex:771: undefined reference to `std::tr1::basic_regex<char, std::tr1::regex_traits<char> >::_M_compile()'
/tmp/cc0g3GUE.o: In function `bool std::tr1::regex_match<char const*, char,     std::tr1::regex_traits<char> >(char const*, char const*, std::tr1::basic_regex<char, std::tr1::regex_traits<char> > const&, std::bitset<11u>)':
/usr/include/c++/4.5/tr1_impl/regex:2144: undefined reference to `bool std::tr1::regex_match<char const*, std::allocator<std::tr1::sub_match<char const*> >, char,     std::tr1::regex_traits<char> >(char const*, char const*, std::tr1::match_results<char     const*, std::allocator<std::tr1::sub_match<char const*> > >&, std::tr1::basic_regex<char, std::tr1::regex_traits<char> > const&, std::bitset<11u>)'
collect2: ld returned 1 exit status

我应该安装哪些软件包以使代码在我的电脑上运行?

1 个答案:

答案 0 :(得分:0)

你需要查看gcc的c ++ 0x库支持,因为我认为Regex还没有完成

http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.200x