0

I am trying to use the GNU C library regex functionality in my C++ project, particularly I'm trying to use the regex_t regcomp, regexec, regfree functions. Upon compilation I get errors stating that these symbols are undefined:

me> g++ -I/me/myheaders/ -c RootGenerator.cpp -o RootGenerator.o -std=gnu++0x -Wall

RootGenerator.cpp: In function ‘std::string findFirstFileInCurrentDirectory(std::string)’:
RootGenerator.cpp:1072: error: ‘regex_t’ was not declared in this scope
RootGenerator.cpp:1072: error: expected ‘;’ before ‘re’
RootGenerator.cpp:1073: error: ‘re’ was not declared in this scope
RootGenerator.cpp:1073: error: ‘REG_EXTENDED’ was not declared in this scope
RootGenerator.cpp:1073: error: ‘REG_NOSUB’ was not declared in this scope
RootGenerator.cpp:1073: error: ‘regcomp’ was not declared in this scope
RootGenerator.cpp:1074: error: expected ‘;’ before ‘int’
RootGenerator.cpp:1084: error: ‘status’ was not declared in this scope
RootGenerator.cpp:1084: error: ‘regexec’ was not declared in this scope
RootGenerator.cpp:1092: error: ‘REG_NOMATCH’ was not declared in this scope
RootGenerator.cpp:1108: error: ‘regfree’ was not declared in this scope

I realize that the regex header is a TR1 implementation and is therefore experimental for my version of GCC. I added the -std=gnu++0x compiler option according to the compiler warning recieved when first trying to compile but this doesn't seem to fix the issue. Is this an issue of the system not recognizing and adding paths to "experimental" headers? Are there additional include paths or compiler options that I need to specify?

As an additional note, I noticed in Eclipse/CDT that under the "includes" tab in the Project Explorer view, it shows a list of the system header paths. It lists many header files under the /user/include/c++/4.4.4 path tab, but It doesn't list the regex header. I think this is also reaffirming that there is a setting issue.

JonnyB
  • 335
  • 1
  • 3
  • 13
  • 2
    Just a sanity check; your source file is definitely #including the relevant header? – Oliver Charlesworth May 31 '13 at 16:28
  • 2
    When it comes to regex, a lot is missing> http://stackoverflow.com/questions/12530406/is-gcc4-7-buggy-about-regular-expressions http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.2011 – Johan Lundberg May 31 '13 at 16:31
  • Yeah, GCC hasn't implemented `` yet. – chris May 31 '13 at 16:32
  • @OliCharlesworth, good question and check. I have `#include ` at the top of my source file. – JonnyB May 31 '13 at 16:36
  • Gcc 4.4.4 is pretty old now. – ams May 31 '13 at 16:36
  • 1
    Lol, yes Gcc 4.4.4 is pretty old. Unfortunately my company has stringent IT requirements and follows the RHEL distribution change lifecycle to a tee. They don't really allow us to customize to much. – JonnyB May 31 '13 at 16:38
  • I may be able to build and use the boost regex library. This may be the best solution. I was just hoping I could compile and link a single executable and not have to worry about distributing .so files. – JonnyB May 31 '13 at 16:40
  • 1
    None of the symbols in the error are name-space qualified - do you have the appropriate "using namespace tr1" in your code? – kfsone May 31 '13 at 23:09
  • @ksfone I did not specify this namespace either. Thanks for the tip, and I will keep that in mind if I plan to use the TR1 implementation in the future. The real issue however, as specified in the answer, was not including the correct header to begin with. – JonnyB Jun 03 '13 at 13:20

1 Answers1

0

Found the problem:

#include <regex>

should be

#include <regex.h>

The regex.h header is the GNU C library implementation of regex, containing the functions I was trying to use in my source. The regex header is the TR1 (and incomplete) regex implemntation. So @Oli, I wasn't referencing the relevant header after all!

JonnyB
  • 335
  • 1
  • 3
  • 13