首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >libstdc++ -由于tr1/regex导致编译失败

libstdc++ -由于tr1/regex导致编译失败
EN

Stack Overflow用户
提问于 2011-01-18 06:21:15
回答 1查看 2.3K关注 0票数 0

我在我的OpenSUSE 11.3上安装了以下软件包:

代码语言:javascript
复制
i | libstdc++45       | Standard shared library for C++                 | package
i | libstdc++45-devel | Contains files and libraries for development    | package

但是当我尝试编译这段C++代码时:

代码语言:javascript
复制
#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;
}

使用

代码语言:javascript
复制
g++ -pedantic -g -O1 -o ./main.o ./main.cpp

它输出以下错误:

代码语言:javascript
复制
/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

我应该(卸载)安装什么包才能使代码在我的PC上工作?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-01-18 06:37:52

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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4718568

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档