11

I get a linker error with the following code:

#include <regex>

int main()
{
    std::regex rgx("ello");
    return 0;
}

test.o: In function `basic_regex':
/usr/lib/gcc/i586-redhat-linux/4.4.1/../../../../include/c++/4.4.1/tr1_impl/regex:769: undefined reference to `std::basic_regex<char, std::regex_traits<char> >::_M_compile()'
collect2: ld returned 1 exit status
Scott
  • 5,135
  • 12
  • 57
  • 74

2 Answers2

8

From gcc-4.4.1/include/c++/4.4.1/tr1_impl/regex

template <...>
class basic_regexp {
...
   private:
      /**
       * @brief Compiles a regular expression pattern into a NFA.
       * @todo Implement this function.
       */
      void _M_compile();

I guess it's not ready yet.

UPDATE: current bleeding edge GCC (SVN @153546) doesn't appear to have the implementation yet.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362
  • Well, I guess I'm not using the bleeding edge gcc either. – Scott Oct 26 '09 at 06:00
  • 10
    I must say it's very sadistic to do this to developers! One should at LEAST print a warning at compile time saying that it's not implemented, to avoid developers loosing so much time thinking they are doing something wrong. – krico Aug 14 '10 at 20:27
  • Yeah, cruel indeed. Porting a pile of C++ code from MS Windows Visual Studio 10 over to linux that uses std::regex, and it compiles just peach without issue on GCC 4.4.7.. so the headers tell the compiler that all is well. But once the linker step comes in it blows up along the lines of a ton of "undefined reference to `std::basic_regex..." – Minok Nov 20 '15 at 00:35
1

you may get the implmentation status from: http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt01ch01.html#manual.intro.status.standard.tr1

to use regex, you could install boost library and their tr1 has already included regex.

koyeung
  • 134
  • 1
  • 2