13

I can create .o file with g++ -c test.cpp -std=c++0x, but cant link it, got next errors:

test.cpp:(.text+0xe5): undefined reference to `std::regex_iterator<char const*, char, std::regex_traits<char> >::regex_iterator(char const*, char const*, std::basic_regex<char, std::regex_traits<char> > const&, std::bitset<11u>)'
test.cpp:(.text+0xf1): undefined reference to `std::regex_iterator<char const*, char, std::regex_traits<char> >::regex_iterator()'

Code:

#include <regex> 
#include <iostream> 

#include <string.h>

typedef std::regex_iterator<const char *> Myiter; 
int main() 
{ 
    const char *pat = "axayaz"; 
    Myiter::regex_type rx("a"); 
    Myiter next(pat, pat + strlen(pat), rx); 
    Myiter end; 


    return (0); 
} 
4
  • 1
    Which version of GCC? <regex> isn't actually implemented up to and inluding 4.6.2. Also, why not use std::cregex_iterator instead? Commented Dec 19, 2011 at 13:14
  • 1
    have you considered using the boost regex libraries? Both boost::regex and boost::xpressive are fully functional. Commented Dec 19, 2011 at 15:05
  • i know man, i used this staff, but for now i cant.. Commented Dec 19, 2011 at 15:26
  • 1
    This might help someone: Don't be fooled if you think you have a regex implementation in gcc 4.7.1. Look closely at the content of regex.h and you'll see it full of TODO entries and unimplemented functions. Commented Jan 30, 2013 at 20:59

1 Answer 1

17

The GNU C++ standard library supports <regex>, but not until version 4.9.0. (The headers were present in earlier versions, but were unusable.)

The other compilers don't support it, as far as I can see.

You can use a different library if you use an older GCC.

Sign up to request clarification or add additional context in comments.

1 Comment

Both MSVC and Clang support <regex>. Actually regex is pretty much the only part of C++11 where GCC lags behind other compilers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.