The GRETA Regular Expression Template Archive
Home Products Articles Crew
..:: Greta ::..
 
  [All rights reserved: http://www.nk975.com/sswater/en/greta/index.htm]  
     
      GRETA gives you all the power of Perl 5 regular expressions in your C++ applications. The GRETA homepage is http://research.microsoft.com/projects/greta/. Today, we will discuss neither regular expression itself nor template classes in greta library, because you can get familiar with them at GRETA homepage. I will explain how to add and build greta library in Visual C++ correctly, step by step.  
 

Download
 
      Download greta's SOURCE CODE at GRETA homepage. For example: GRETA 2.6.4 for VC6, you will get 'greta-2.6.4-vc6.zip'. Or you can download it from this site.  
      Please DO NOT download *.lib file for greta (such as greta.lib etc). You may find greta in *.lib out of microsoft. But the greta.lib may not satisfy your needs, or it may generate link errors.  
 

How To Use
 
      GRETA library has 6 program files:
  • regexpr2.h
  • regexpr2.cpp
  • syntax2.h
  • syntax2.cpp
  • restack.h
  • reimpl2.h

    You can use them in 2 ways:
    (1) Add these files into your project directly. ( not recommended )
    (2) Create a new 'Win32 Static Library' project for GRETA in your workspace.

 
 

Method 1: Add Into Project Directly ( not recommended )
 
      To add into project directly is not recommended. If your project uses precompiled header file, please add #include "stdafx.h" into regexpr2.cpp and syntax2.cpp.  
 

Method 2: Create New 'Win32 Static Library' Project
 
  Step by step:

Step 1: Create a blank workspace. For example 'Test':


Step 2: Create the main project which will use greta. For example 'Console' type 'Main':


Step 3: Create the greta project. Select 'Win32 Static Library' and make it the dependency of Main project. After press OK button, let the 'Pre-Compiled header' and 'MFC Support' unchecked.


Step 4: Copy those 6 program files from Greta zip package into the Greta project's directory and add them to project.


Step 5: Copy one of the example codes into the main() function. Change the #include "regexpr2.h" to #include "..\greta\regexpr2.h". These examples are in the html file from the GRETA zip package. Select 'Main' project the active project, then compile the project and run:


You will get the result :


Now we have successfully finished the project with greta. [Download example project]

If your project uses UNICODE or your main project is dll type, please go on with the following.
 
 
 
..:: Advanced ::..
 

1. UNICODE version
 
  If your project (which uses greta) is UNICODE version, you must make Greta project to be UNICODE version. For example:

Step 1: Add a 'Unicode Debug' configuration for Greta project:


Step 2: At the project settings, add '_UNICODE' and 'UNICODE' macro into the C++ General Preprocessor defininitions of the corresponding 'Unicode Debug' Configuration:


Step 3: Repeat step 1 and step 2 for 'Main' project and for 'Release' configuration. You will get 'Unicode Debug' and 'Unicode Release' configuration for both Greta and your main project.
 
 

2. Runtime library
 
  In many cases, for instance your main project is dll, you must make sure that the greta uses the same runtime library as your main project, or you will get a link error.

Step 1: To determine which runtime library your main project uses:


Step 2: Select the same runtime library for greta project. Then you can link successfully.
 
 

3. Why to download greta.lib is disagreedd
 
      Q: Why to download greta.lib is disagreed and why greta.lib downloaded may generate link error?  
      A: Because the reason of "UNICODE version" and "Runtime library". Because it is unkown whether the greta.lib downloaded is UNICODE version or not, and it is unkown which runtime library the greta.lib downloaded uses, so it may generate link error.  
 
 
..:: Relatives ::..