Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

std::regex -- is there some lib that needs to be linked?

Tags:

c++

regex

c++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
like image 472
Scott Avatar asked Oct 26 '09 05:10

Scott


2 Answers

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.

like image 90
Employed Russian Avatar answered Nov 15 '22 02:11

Employed Russian


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.

like image 1
koyeung Avatar answered Nov 15 '22 00:11

koyeung