无法编译正则表达式

时间:2014-05-20 08:30:41

标签: c++ regex

我正在尝试在C ++中使用正则表达式库,甚至一个简单的例子都没有编译。

#include <cstring>
#include <string>
#include <iostream>
#include <regex>

extern "C"
{
        #include <stdio.h>
        #include <stdlib.h>
}

int main (int argc, char *argv[])
{
        std::string test = "some string";
        std::regex regex("s");
        std::string replacement("");

        std::regex_replace(test, regex, replacement);
}

要编译,我使用-std = c ++ ox标志用g ++编译。

我收到的错误的一部分是:

/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/tr1_impl/regex:2388: warning: inline function ‘_Out_iter std::regex_replace(_Out_iter, _Bi_iter, _Bi_iter, const std::basic_regex<_Ch_type, _Rx_traits>&, const std::basic_string<_Ch_type, std::char_traits<_Ch_type>, std::allocator<_Tp2> >&, std::regex_constants::match_flag_type) [with _Out_iter = std::back_insert_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, _Bi_iter = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, _Rx_traits = std::regex_traits<char>, _Ch_type = char]’ used but never defined
/tmp/ccld1yyB.o: In function `std::basic_regex<char, std::regex_traits<char> >::basic_regex(char const*, unsigned int)':
test.cpp:(.text._ZNSt11basic_regexIcSt12regex_traitsIcEEC2EPKcj[_ZNSt11basic_regexIcSt12regex_traitsIcEEC5EPKcj]+0x96): undefined reference to `std::basic_regex<char, std::regex_traits<char> >::_M_compile()'

有什么想法吗?

0 个答案:

没有答案