Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get PCRE to work with C++?

Tags:

This is a newbie question but I hope I can express my question as clearly as possible.

I'm trying to do pattern matching in C++.

I've downloaded the Win32 version of PCRE from here and I've placed the downloaded pcre3.dll and pcreposix3.dll files into the folder of Dev-CPP's lib folder (I'm using Bloodshed Dev-C++ 4.9.9 IDE).

I've also downloaded a pcrecpp.h header file and have it in the same directory I'm writing the following code (not writing actually. I'm coping example code from a PDF tutorial named PCRE- Perl Compatible Regular Express).

But I can't get it to work. The code is as follows:

    #include <iostream>
    #include <string>
    #include <pcrecpp.h>

    using namespace std;

    int main()
    {
       int i;
       string s;
       pcrecpp::RE re("(\\w+):(\\d+)");
       if (re.error().length() > 0) {
          cout << "PCRE compilation failed with error: " << re.error() << "\n";
       }
       if (re.PartialMatch("root:1234", &s, &i))
       cout << s << " : " << i << "\n";
    }

When I compile the code, Dev-C++ gives me a lot of errors including: "`pcrecpp' has not been declared" and "RE" undeclared.

How should I deal with the downloaded files and fix my problem? Or is there something obvious that I'm missing?